{"id":77047,"date":"2025-04-18T08:00:00","date_gmt":"2025-04-17T23:00:00","guid":{"rendered":"https:\/\/www.creationline.com\/tech-blog\/?p=77047"},"modified":"2025-04-17T18:11:52","modified_gmt":"2025-04-17T09:11:52","slug":"langchain%e3%81%aerag%e3%83%81%e3%83%a5%e3%83%bc%e3%83%88%e3%83%aa%e3%82%a2%e3%83%ab%e3%82%92%e3%82%84%e3%81%a3%e3%81%a6%e3%81%bf%e3%81%9f%ef%bc%88%e5%be%8c%e7%b7%a8%ef%bc%89-langchain-langgraph-ra","status":"publish","type":"post","link":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047","title":{"rendered":"LangChain\u306eRAG\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u3084\u3063\u3066\u307f\u305f\uff08\u5f8c\u7de8\uff09 #langchain #langgraph #rag #azure #openai"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u306f\u3058\u3081\u306b<\/h2>\n\n\n\n<p>\u672c\u7a3f\u3067\u306f <a href=\"https:\/\/www.langchain.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">LangChain<\/a> \u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb <a href=\"https:\/\/python.langchain.com\/docs\/tutorials\/qa_chat_history\/\" target=\"_blank\" rel=\"noreferrer noopener\">Build a Retrieval Augmented Generation (RAG) App: Part 2<\/a> \u3092 <a href=\"https:\/\/azure.microsoft.com\/ja-jp\/products\/ai-services\/openai-service\" target=\"_blank\" rel=\"noreferrer noopener\">Azure OpenAI<\/a> \u3092\u4f7f\u3063\u3066\u5b9f\u65bd\u3057\u3066\u307f\u305f\u8a18\u9332\u3067\u3059\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/python.langchain.com\/docs\/tutorials\/rag\/\" target=\"_blank\" rel=\"noreferrer noopener\">Part 1<\/a>\u3092\u5b9f\u65bd\u3057\u3066\u307f\u305f\u8a18\u9332\u3067\u3042\u308b<a href=\"https:\/\/www.creationline.com\/tech-blog\/77039\" target=\"_blank\" rel=\"noreferrer noopener\">\u524d\u7de8<\/a>\u304b\u3089\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p>LLM\u306e\u307f\u306b\u57fa\u3065\u3044\u305f\u751f\u6210AI\u3067\u306f\u3001LLM\u30e2\u30c7\u30eb\u304c\u77e5\u3089\u306a\u3044\u5185\u5bb9\u3092\u7121\u7406\u306b\u56de\u7b54\u3057\u3088\u3046\u3068\u3059\u308b\u5834\u5408\u3001\u304a\u304b\u3057\u306a\u7d50\u679c\u3092\u751f\u6210\u3057\u3066\u3057\u307e\u3044\u304c\u3061\u3067\u3059\u3002\u4f8b\u3048\u3070\u3001\u793e\u5185\u306e\u307f\u3067\u5171\u6709\u3055\u308c\u3066\u3044\u308b\u6587\u7ae0\u306b\u3064\u3044\u3066\u77e5\u3089\u306a\u3044\u3068\u56de\u7b54\u3059\u308b\u306a\u3089\u307e\u3060\u3057\u3082\u3001\u307e\u3063\u305f\u304f\u9593\u9055\u3063\u305f\u5185\u5bb9\u3092\u751f\u6210\u3055\u308c\u3066\u306f\u56f0\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u3053\u3067\u3001RAG (Retrieval Augmented Generation; \u691c\u7d22\u62e1\u5f35\u751f\u6210) \u3068\u3044\u3046\u691c\u7d22\u6280\u8853\u3068\u751f\u6210AI\u3092\u7d44\u307f\u5408\u308f\u305b\u305f\u30a2\u30d7\u30ed\u30fc\u30c1\u306e\u51fa\u756a\u3067\u3059\u3002\u5148\u306e\u4f8b\u3067\u8a00\u3048\u3070\u3001\u691c\u7d22\u3067\u5f97\u305f\u793e\u5185\u6587\u7ae0\u3092\u3082\u3068\u306b\u3001\u751f\u6210AI\u3067\u56de\u7b54\u3092\u4f5c\u6210\u3059\u308b\u306e\u3067\u3001\u6b63\u3057\u3044\u7b54\u3048\u3067\u3042\u308b\u53ef\u80fd\u6027\u304c\u9ad8\u307e\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>RAG\u306b\u3064\u3044\u3066\u306f\u4ed6\u8a18\u4e8b\u3082\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.creationline.com\/tech-blog\/68030\" target=\"_blank\" rel=\"noreferrer noopener\">\u3010RAG\u304c\u308f\u304b\u308b\u3011\u793e\u5185\u52c9\u5f37\u4f1a\u306e\u5185\u5bb9\u3092\u7279\u5225\u516c\u958b\uff01<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.creationline.com\/tech-blog\/71848\" target=\"_blank\" rel=\"noreferrer noopener\">\u3010CL\u304f\u3093\u30d6\u30ed\u30b0\u3011Tokyo RAG user group Meetup \u3067\u5f0a\u793e\u30a8\u30f3\u30b8\u30cb\u30a2\u304c\u8b1b\u6f14\u3057\u307e\u3057\u305f\uff01<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.creationline.com\/tech-blog\/71715\" target=\"_blank\" rel=\"noreferrer noopener\">\u3010\u30a8\u30f3\u30bf\u30fc\u30d7\u30e9\u30a4\u30baLLM\u3011\u793e\u5185\u30c7\u30fc\u30bf\u3092\u5143\u306b\u56de\u7b54\u3057\u3066\u304f\u308c\u308bChatGPT\u3092\u4f5c\u308b\u306b\u306f\uff1f RAG\u30fbLLM\u6280\u8853\u3092\u5229\u7528\u3057\u3066\u4fa1\u5024\u3042\u308b\u4f01\u696d\u72ec\u81ea\u306eAI\u3092\u4f5c\u308b\u305f\u3081\u306e\u30c6\u30af\u30cb\u30c3\u30af<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.creationline.com\/tech-blog\/74639\" target=\"_blank\" rel=\"noreferrer noopener\">Azure AI Search\u3067RAG\u3057\u3066\u307f\u3088\u3046\uff01 \u30c1\u30e3\u30c3\u30c8\u30d7\u30ec\u30a4\u30b0\u30e9\u30a6\u30f3\u30c9\u3068Web\u30a2\u30d7\u30ea\u7de8<\/a><\/li>\n<\/ul>\n\n\n\n<p>LLM\u3092\u4f7f\u7528\u3057\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u958b\u767a\u3059\u308b\u305f\u3081\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3042\u308bLangChain\u306e<a href=\"https:\/\/python.langchain.com\/docs\/tutorials\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/a>\u306b\u306f\u7c21\u5358\u306aRAG\u3092\u5b9f\u88c5\u3059\u308b\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306b\u672c\u8a18\u4e8b\u306b\u72ec\u81ea\u306e\u5185\u5bb9\u3082\u542b\u3081\u3066\u3084\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u524d\u63d0<\/h2>\n\n\n\n<p>\u672c\u7a3f\u3067\u306f\u6b21\u306e\u74b0\u5883\u3092\u524d\u63d0\u3068\u3057\u3066\u9032\u3081\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.python.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python<\/a> 3.13.2<\/li>\n\n\n\n<li><a href=\"https:\/\/www.langchain.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">LangChain<\/a> 0.3.14<\/li>\n\n\n\n<li><a href=\"https:\/\/www.langchain.com\/langgraph\" target=\"_blank\" rel=\"noreferrer noopener\">LangGraph<\/a> 0.3.27<\/li>\n<\/ul>\n\n\n\n<p>\u591a\u5c11\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u9055\u3044\u306f\u8aad\u307f\u66ff\u3048\u3066\u304f\u3060\u3055\u3044\u3002\u307e\u305f\u3001\u6b21\u306e\u6709\u6599\u30ea\u30bd\u30fc\u30b9\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Azure OpenAI<\/li>\n\n\n\n<li>gpt-4o (2024-08-06)<\/li>\n\n\n\n<li>text-embedding-ada-002 (2)<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u3061\u3089\u3082\u591a\u5c11\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u9055\u3044\u306f\u8aad\u307f\u66ff\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u65bd<\/h2>\n\n\n\n<p>\u3082\u3046\u4e00\u3064\u306e<a href=\"https:\/\/python.langchain.com\/docs\/tutorials\/qa_chat_history\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/a>\u304b\u3089\u3082\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u306f\u3001\u7279\u5b9a\u306e\u30a6\u30a7\u30d6\u30da\u30fc\u30b8\u306e\u5185\u5bb9\u306b\u57fa\u3044\u3066\u3001\u8cea\u7591\u5fdc\u7b54\u30922\u56de\u7d99\u7d9a\u3059\u308bLangGraph\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002\u672c\u8a18\u4e8b\u306e\u72ec\u81ea\u8981\u7d20\u3068\u3057\u3066\u3001\u5f0a\u793e\u306e\u300c\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u300d\u306b\u5bfe\u3059\u308b\u8cea\u554f\u306b\u7b54\u3048\u3089\u308c\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u56de\u7b54\u306f\u5f0a\u793e Tech blog \u306e\u8a18\u4e8b\u300c<a href=\"https:\/\/www.creationline.com\/tech-blog\/76913\" target=\"_blank\" rel=\"noreferrer noopener\">\u307f\u3093\u306a\u3067\u80b2\u3080\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u30fb\u6b63\u5f0f\u5c0e\u5165\u3092\u6c7a\u5b9a\u3057\u307e\u3057\u305f<\/a>\u300d\u306b\u8a18\u8f09\u3055\u308c\u305f\u5185\u5bb9\u306b\u57fa\u3065\u304f\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Part 1 \u3068\u91cd\u8907\u3059\u308b\u90e8\u5206<\/h3>\n\n\n\n<p>\u5192\u982d\u90e8\u5206\u306f <a href=\"https:\/\/python.langchain.com\/docs\/tutorials\/rag\/\" target=\"_blank\" rel=\"noreferrer noopener\">Part 1<\/a> \u3068\u540c\u3058\u30b3\u30fc\u30c9\u306a\u306e\u3067\u3001\u89e3\u8aac\u3092\u7701\u304d\u307e\u3059\u3002\u8a73\u7d30\u306f<a href=\"https:\/\/www.creationline.com\/tech-blog\/77039\" target=\"_blank\" rel=\"noreferrer noopener\">\u524d\u7de8<\/a>\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import os\nfrom dotenv import load_dotenv\nload_dotenv()\n\nfrom langchain.chat_models import init_chat_model\n\nllm = init_chat_model(\n    model=os.getenv(\"AZURE_OPENAI_MODEL\"),\n    model_provider=\"azure_openai\",\n    azure_endpoint=os.getenv(\"AZURE_OPENAI_ENDPOINT\"),\n    api_key=os.getenv(\"AZURE_OPENAI_API_KEY\"),\n    api_version=os.getenv(\"AZURE_OPENAI_API_VERSION\"),\n)\n\nfrom langchain_openai import AzureOpenAIEmbeddings\n\nembeddings = AzureOpenAIEmbeddings(\n    model=os.getenv(\"AZURE_OPENAI_EMBEDDING_MODEL\"),\n    azure_endpoint=os.getenv(\"AZURE_OPENAI_ENDPOINT\"),\n    api_key=os.getenv(\"AZURE_OPENAI_API_KEY\"),\n    openai_api_version=os.getenv(\"AZURE_OPENAI_API_VERSION\"),\n)\n\nfrom langchain_core.vectorstores import InMemoryVectorStore\n\nvector_store = InMemoryVectorStore(embeddings)\n\nimport bs4\nfrom langchain_community.document_loaders import WebBaseLoader\n\nloader = WebBaseLoader(\n    web_paths=(\"https:\/\/www.creationline.com\/tech-blog\/hr\/76913\",),\n    bs_kwargs=dict(\n        parse_only=bs4.SoupStrainer(\n            class_=(\"content_post\", \"tech_header\")\n        )\n    ),\n)\ndocs = loader.load()\n\nfrom langchain_text_splitters import RecursiveCharacterTextSplitter\n\ntext_splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder(\n    separators=[\"\\n\\n\", \"\\n\", \"\u3002\"],\n    chunk_size=200, chunk_overlap=100\n)\nall_splits = text_splitter.split_documents(docs)\n\n_ = vector_store.add_documents(documents=all_splits)<\/pre>\n\n\n\n<p>\u4e00\u70b9\u3060\u3051 Part 1 \u3068\u5909\u66f4\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    chunk_size=200, chunk_overlap=100<\/pre>\n\n\n\n<p>\u30c1\u30e3\u30f3\u30af\u30b5\u30a4\u30ba\u3068\u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u3092\u305d\u308c\u305e\u308c2\u500d\u306e\u5024\u306b\u3057\u3066\u3044\u307e\u3059\u3002\u7406\u7531\u306f\u5f8c\u8ff0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30b0\u30e9\u30d5\u306e\u69cb\u6210(1)<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from langgraph.graph import MessagesState, StateGraph\n\ngraph_builder = StateGraph(MessagesState)<\/pre>\n\n\n\n<p>LangGraph\u306b\u3064\u3044\u3066\u306f\u904e\u53bb\u30d6\u30ed\u30b0\u300c<a href=\"https:\/\/www.creationline.com\/tech-blog\/75504]\" target=\"_blank\" rel=\"noreferrer noopener\">LangGraph\u3092LLM\u306a\u3057\u3067\u3061\u3087\u3063\u3068\u89e6\u3063\u3066\u307f\u3088\u3046<\/a>\u300d\u300c<a href=\"https:\/\/www.creationline.com\/tech-blog\/75615\" target=\"_blank\" rel=\"noreferrer noopener\">LangGraph\u3068Azure OpenAI\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u307f\u3088\u3046<\/a>\u300d\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30c4\u30fc\u30eb\u306e\u4f5c\u6210<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from langchain_core.tools import tool\n\n@tool(response_format=\"content_and_artifact\")\ndef retrieve(query: str):\n    \"\"\"Retrieve information related to a query.\"\"\"\n    retrieved_docs = vector_store.similarity_search(query, k=2)\n    serialized = \"\\n\\n\".join(\n        (f\"Source: {doc.metadata}\\n\" f\"Content: {doc.page_content}\")\n        for doc in retrieved_docs\n    )\n    return serialized, retrieved_docs<\/pre>\n\n\n\n<p>\u3053\u3053\u3067\u306fLangGraph\u306eTool calling\u3092\u4f7f\u3063\u3066\u691c\u7d22\u300c\u30c4\u30fc\u30eb\u300d\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002Tool calling\u306e\u3057\u304f\u307f\u306b\u3064\u3044\u3066\u306f\u904e\u53bb\u8a18\u4e8b\u300c<a href=\"https:\/\/www.creationline.com\/tech-blog\/76708\" target=\"_blank\" rel=\"noreferrer noopener\">LangGraph\u306eTool calling\u3067OpenAI API\u306eFunction calling\u3092\u8a66\u3057\u3066\u307f\u3088\u3046<\/a>\u300d\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p>\u30d9\u30af\u30c8\u30eb\u30b9\u30c8\u30a2\u304b\u3089\u7c21\u5358\u306a<a href=\"https:\/\/python.langchain.com\/docs\/concepts\/vectorstores\/#similarity-search\" target=\"_blank\" rel=\"noreferrer noopener\">\u985e\u4f3c\u691c\u7d22 (similarity_search)<\/a>\u3092\u7528\u3044\u3066\u30c1\u30e3\u30f3\u30af\u3092\u53d6\u308a\u51fa\u3057\u307e\u3059\u3002\u30c1\u30e3\u30f3\u30af\u306e\u500b\u6570\u306f <code>k=2<\/code> \u3067top_k\u306e\u6307\u5b9a\u304c\u3042\u308b\u901a\u308a\u30012\u500b\u3067\u3059\u3002\u305d\u3057\u3066\u30c1\u30e3\u30f3\u30af\u306e\u5185\u5bb9\u3060\u3051\u3067\u306a\u304f\u3001\u30e1\u30bf\u30c7\u30fc\u30bf\u3082\u9023\u7d50\u3057\u3066\u8fd4\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u306a\u304a\u3001\u30b3\u30e1\u30f3\u30c8\u90e8\u5206\u306e\u300c <code>\"\"\"Retrieve information related to a query.\"\"\"<\/code> \u300d\u3082\u30c4\u30fc\u30eb\u306b\u5fc5\u8981\u306a\u90e8\u5206\u306a\u306e\u3067\u524a\u9664\u3057\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002\u524a\u9664\u3059\u308b\u3068 <code>ValueError: Function must have a docstring if description not provided.<\/code> \u3068\u3044\u3046\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5206\u5c90\u30ce\u30fc\u30c9<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from langchain_core.messages import SystemMessage\nfrom langgraph.prebuilt import ToolNode\n\ndef query_or_respond(state: MessagesState):\n    llm_with_tools = llm.bind_tools([retrieve])\n    response = llm_with_tools.invoke(state[\"messages\"])\n    return {\"messages\": [response]}<\/pre>\n\n\n\n<p>\u3053\u3053\u3067\u306f\u30e6\u30fc\u30b6\u306e\u5165\u529b <code>state[\"messages\"]<\/code> \u3092Tool calling\u306e\u4ed5\u7d44\u307f\u3067\u3001\u5148\u306e\u30c4\u30fc\u30eb <code>retrieve<\/code> \u3067\u30d9\u30af\u30c8\u30eb\u30b9\u30c8\u30a2\u306e\u554f\u3044\u5408\u308f\u305b\u3092\u884c\u3046\u304b\u3001\u76f4\u63a5\u5fdc\u7b54\u3059\u308b\u304b\u3067\u5206\u5c90\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30c4\u30fc\u30eb\u30ce\u30fc\u30c9<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tools = ToolNode([retrieve])<\/pre>\n\n\n\n<p>\u5148\u306e\u30c4\u30fc\u30eb <code>retrieve<\/code> \u3092\u30c4\u30fc\u30eb\u30ce\u30fc\u30c9\u3068\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u751f\u6210\u30ce\u30fc\u30c9<\/h3>\n\n\n\n<p><code>generate<\/code> \u95a2\u6570\u306f\u5927\u304d\u3044\u306e\u3067\u3001\u5c11\u3057\u305a\u3064\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def generate(state: MessagesState):\n    recent_tool_messages = []\n    for message in reversed(state[\"messages\"]):\n        if message.type == \"tool\":\n            recent_tool_messages.append(message)\n        else:\n            break\n    tool_messages = recent_tool_messages[::-1]<\/pre>\n\n\n\n<p>\u30c4\u30fc\u30eb\u304c\u751f\u6210\u3057\u305f\u30e1\u30c3\u30bb\u30fc\u30b8\u3092 <code>recent_tool_messages<\/code> \u30ea\u30b9\u30c8\u306b\u8ffd\u52a0\u3057\u3066\u3044\u304d\u307e\u3059\u3002\u6700\u7d42\u7684\u306b <code>tool_messages<\/code> \u30ea\u30b9\u30c8\u306b\u9006\u9806\u306b\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u3053\u3067\u8a00\u3046\u30c4\u30fc\u30eb\u306f <code>retrieve<\/code> \u306a\u306e\u3067\u3001\u30d9\u30af\u30c8\u30eb\u691c\u7d22\u3057\u3066\u5f97\u3089\u308c\u305f\u30c1\u30e3\u30f3\u30af\u304c\u30c4\u30fc\u30eb\u751f\u6210\u30e1\u30c3\u30bb\u30fc\u30b8\u3068\u306a\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    docs_content = \"\\n\\n\".join(doc.content for doc in tool_messages)\n    print(docs_content)\n    system_message_content = (\n        \"You are an assistant for question-answering tasks. \"\n        \"Use the following pieces of retrieved context to answer \"\n        \"the question. If you don't know the answer, say that you \"\n        \"don't know. Use three sentences maximum and keep the \"\n        \"answer concise.\"\n        \"\\n\\n\"\n        f\"{docs_content}\"\n    )<\/pre>\n\n\n\n<p>\u3053\u306e\u6587\u3092\u8a33\u3059\u3068\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u3042\u306a\u305f\u306f\u8cea\u554f\u5fdc\u7b54\u30bf\u30b9\u30af\u306e\u30a2\u30b7\u30b9\u30bf\u30f3\u30c8\u3067\u3059\u3002\n\u8cea\u554f\u306b\u7b54\u3048\u308b\u305f\u3081\u306b\u3001\u6b21\u306e\u53ce\u96c6\u3055\u308c\u305f\u6587\u8108\u3092\u6d3b\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n\u7b54\u3048\u304c\u5206\u304b\u3089\u306a\u3044\u5834\u5408\u306f\u3001\u5206\u304b\u3089\u306a\u3044\u3068\u8a00\u3044\u307e\u3057\u3087\u3046\u3002\n\u7b54\u3048\u306f\u6700\u5927\u4e09\u6587\u3067\u7c21\u6f54\u306b\u8ff0\u3079\u3066\u304f\u3060\u3055\u3044\u3002<\/pre>\n\n\n\n<p>\u3053\u306e\u5f8c\u306b\u53d6\u5f97\u3057\u305f\u30c1\u30e3\u30f3\u30af\u304c\u7d9a\u304d\u3001\u30b7\u30b9\u30c6\u30e0\u30e1\u30c3\u30bb\u30fc\u30b8\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    conversation_messages = [\n        message\n        for message in state[\"messages\"]\n        if message.type in (\"human\", \"system\")\n        or (message.type == \"ai\" and not message.tool_calls)\n    ]<\/pre>\n\n\n\n<p>\u3053\u3053\u3067\u306f <code>state[\"messages\"]<\/code> \u306b\u542b\u307e\u308c\u3066\u3044\u308b\u30e1\u30c3\u30bb\u30fc\u30b8\u304b\u3089\u3001\u7279\u5b9a\u306e\u6761\u4ef6\u306b\u5408\u81f4\u3057\u305f\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u53d6\u308a\u51fa\u3057\u3066 <code>conversation_messages<\/code> \u30ea\u30b9\u30c8\u3092\u65b0\u3057\u304f\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002\u5177\u4f53\u7684\u306b\u306f\u3001<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4eba\u9593(<code>human<\/code>)\u304b\u30b7\u30b9\u30c6\u30e0(<code>system<\/code>)\u306e\u30e1\u30c3\u30bb\u30fc\u30b8<\/li>\n\n\n\n<li>AI(<code>ai<\/code>)\u304b\u3064Tool calling\u3092\u884c\u3063\u3066\u3044\u306a\u3044\u30e1\u30c3\u30bb\u30fc\u30b8<\/li>\n<\/ul>\n\n\n\n<p>\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    prompt = [SystemMessage(system_message_content)] + conversation_messages<\/pre>\n\n\n\n<p>\u751f\u6210AI\u306b\u6e21\u3059\u30d7\u30ed\u30f3\u30d7\u30c8\u3068\u3057\u3066\u3001\u5148\u306b\u751f\u6210\u3057\u305f\u30b7\u30b9\u30c6\u30e0\u30e1\u30c3\u30bb\u30fc\u30b8\u3068\u4f1a\u8a71\u5c65\u6b74\u3092\u9023\u7d50\u3057\u305f\u3082\u306e\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    response = llm.invoke(prompt)\n    return {\"messages\": [response]}<\/pre>\n\n\n\n<p>\u751f\u6210AI\u306b\u30d7\u30ed\u30f3\u30d7\u30c8\u3092\u6e21\u3057\u3066\u3001\u7d50\u679c\u3092\u5f97\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30b0\u30e9\u30d5\u306e\u69cb\u6210(2)<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from langgraph.graph import END\nfrom langgraph.prebuilt import ToolNode, tools_condition\n\ngraph_builder.add_node(query_or_respond)\ngraph_builder.add_node(tools)\ngraph_builder.add_node(generate)\n\ngraph_builder.set_entry_point(\"query_or_respond\")\ngraph_builder.add_conditional_edges(\n    \"query_or_respond\",\n    tools_condition,\n    {END: END, \"tools\": \"tools\"},\n)\ngraph_builder.add_edge(\"tools\", \"generate\")\ngraph_builder.add_edge(\"generate\", END)\n\nfrom langgraph.checkpoint.memory import MemorySaver\n\nmemory = MemorySaver()\ngraph = graph_builder.compile(checkpointer=memory)\n\nconfig = {\"configurable\": {\"thread_id\": \"abc123\"}}<\/pre>\n\n\n\n<p>\u30b0\u30e9\u30d5\u3092\u69cb\u6210\u3057\u307e\u3059\u3002\u3053\u306e\u969b\u3001\u4f1a\u8a71\u5c65\u6b74\u3092\u30e1\u30e2\u30ea\u4fdd\u6301\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002\u8a73\u3057\u304f\u306f\u904e\u53bb\u8a18\u4e8b\u300c<a href=\"https:\/\/www.creationline.com\/tech-blog\/75785]\" target=\"_blank\" rel=\"noreferrer noopener\">LangGraph\u306e\u4f1a\u8a71\u5c65\u6b74\u3092\u30e1\u30e2\u30ea\u4fdd\u6301\u3057\u3088\u3046<\/a>\u300d\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8cea\u7591\u5fdc\u7b54<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">input_messages = [\n    \"\u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3\u306e\u300c\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u300d\u3068\u306f\uff1f\",\n    \"\u8cbb\u7528\u306e\u4e0a\u9650\u306f\u3044\u304f\u3089\u3067\u3059\u304b\uff1f\",\n]\n\nfor input_message in input_messages:\n    for step in graph.stream(\n        {\"messages\": [{\"role\": \"user\", \"content\": input_message}]},\n        stream_mode=\"values\",\n        config=config,\n    ):\n        step[\"messages\"][-1].pretty_print()<\/pre>\n\n\n\n<p>\u307e\u305a\u300c\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u300d\u3068\u306f\u4f55\u304b\u3092\u805e\u3044\u3066\u3001\u3055\u3089\u306b\u88dc\u52a9\u3055\u308c\u308b\u8cbb\u7528\u306e\u4e0a\u9650\u3092\u805e\u3044\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7d50\u679c<\/h3>\n\n\n\n<p>\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">(langgraph) % .\/61_rag_tutorial_2.py\n================================ Human Message =================================\n\n\u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3\u306e\u300c\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u300d\u3068\u306f\uff1f\n================================== Ai Message ==================================\nTool Calls:\n  retrieve (call_uY598LFs8TtliXjHKze5hmq3)\n Call ID: call_uY598LFs8TtliXjHKze5hmq3\n  Args:\n    query: \u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3 \u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\n================================= Tool Message =================================\nName: retrieve\n\nSource: {'source': 'https:\/\/www.creationline.com\/tech-blog\/hr\/76913'}\nContent: \u3010\u672c\u984c\u306b\u5165\u308b\u524d\u306b\u3011\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u3068\u306f\u4f55\u304b\uff1f\n\nSource: {'source': 'https:\/\/www.creationline.com\/tech-blog\/hr\/76913'}\nContent: 2024\u5e747\u6708\u304b\u3089\u30c8\u30e9\u30a4\u30a2\u30eb\u904b\u7528\u3092\u59cb\u3081\u305f\u300c\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u300d\u306f\u3001\u30e1\u30f3\u30d0\u30fc\u4e00\u4eba\u3072\u3068\u308a\u306e\u30b9\u30ad\u30eb\u5411\u4e0a\u3084\u30c1\u30e3\u30ec\u30f3\u30b8\u3092\u5f8c\u62bc\u3057\u3059\u308b\u5236\u5ea6\u3068\u3057\u3066\u3001\u6709\u52b9\u306b\u6a5f\u80fd\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002\u307e\u305f\u3001\u30c8\u30e9\u30a4\u30a2\u30eb\u671f\u9593\u4e2d\u306b\u767a\u751f\u3057\u305f\u3055\u307e\u3056\u307e\u306a\u30b1\u30fc\u30b9\u306b\u3082\u3001\u30ea\u30fc\u30c0\u30fc\u9663\u304c\u4f1a\u793e\u5168\u4f53\u306e\u8996\u70b9\u304b\u3089\u8b70\u8ad6\u3092\u91cd\u306d\u3001\u67d4\u8edf\u306b\u5bfe\u5fdc\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002\nSource: {'source': 'https:\/\/www.creationline.com\/tech-blog\/hr\/76913'}\nContent: \u3010\u672c\u984c\u306b\u5165\u308b\u524d\u306b\u3011\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u3068\u306f\u4f55\u304b\uff1f\n\nSource: {'source': 'https:\/\/www.creationline.com\/tech-blog\/hr\/76913'}\nContent: 2024\u5e747\u6708\u304b\u3089\u30c8\u30e9\u30a4\u30a2\u30eb\u904b\u7528\u3092\u59cb\u3081\u305f\u300c\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u300d\u306f\u3001\u30e1\u30f3\u30d0\u30fc\u4e00\u4eba\u3072\u3068\u308a\u306e\u30b9\u30ad\u30eb\u5411\u4e0a\u3084\u30c1\u30e3\u30ec\u30f3\u30b8\u3092\u5f8c\u62bc\u3057\u3059\u308b\u5236\u5ea6\u3068\u3057\u3066\u3001\u6709\u52b9\u306b\u6a5f\u80fd\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002\u307e\u305f\u3001\u30c8\u30e9\u30a4\u30a2\u30eb\u671f\u9593\u4e2d\u306b\u767a\u751f\u3057\u305f\u3055\u307e\u3056\u307e\u306a\u30b1\u30fc\u30b9\u306b\u3082\u3001\u30ea\u30fc\u30c0\u30fc\u9663\u304c\u4f1a\u793e\u5168\u4f53\u306e\u8996\u70b9\u304b\u3089\u8b70\u8ad6\u3092\u91cd\u306d\u3001\u67d4\u8edf\u306b\u5bfe\u5fdc\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002\n================================== Ai Message ==================================\n\n\u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3\u306e\u300c\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u300d\u306f\u3001\u30e1\u30f3\u30d0\u30fc\u4e00\u4eba\u3072\u3068\u308a\u306e\u30b9\u30ad\u30eb\u5411\u4e0a\u3084\u30c1\u30e3\u30ec\u30f3\u30b8\u3092\u5f8c\u62bc\u3057\u3059\u308b\u305f\u3081\u306e\u5236\u5ea6\u3067\u3059\u30022024\u5e747\u6708\u304b\u3089\u30c8\u30e9\u30a4\u30a2\u30eb\u904b\u7528\u304c\u59cb\u307e\u308a\u3001\u30c8\u30e9\u30a4\u30a2\u30eb\u671f\u9593\u4e2d\u306b\u306f\u30ea\u30fc\u30c0\u30fc\u9663\u304c\u67d4\u8edf\u306b\u5bfe\u5fdc\u3057\u306a\u304c\u3089\u904b\u7528\u306e\u52b9\u679c\u3092\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u3002\n================================ Human Message =================================\n\n\u8cbb\u7528\u306e\u4e0a\u9650\u306f\u3044\u304f\u3089\u3067\u3059\u304b\uff1f\n================================== Ai Message ==================================\nTool Calls:\n  retrieve (call_WjV7MEfSJmwDZXYk2WduZlGh)\n Call ID: call_WjV7MEfSJmwDZXYk2WduZlGh\n  Args:\n    query: \u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3 \u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6 \u8cbb\u7528 \u4e0a\u9650\n================================= Tool Message =================================\nName: retrieve\n\nSource: {'source': 'https:\/\/www.creationline.com\/tech-blog\/hr\/76913'}\nContent: \u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u3068\u306f\u3001\u30b9\u30ad\u30eb\u958b\u767a\u8cbb\u7528\u306e\u4e00\u90e8\u3092\u4f1a\u793e\u304c\u8ca0\u62c5\u3059\u308b\u3053\u3068\u3067\u3001\u30e1\u30f3\u30d0\u30fc\u306e\u7686\u3055\u3093\u306e\u30b9\u30ad\u30eb\u958b\u767a\u3092\u5968\u52b1\u3059\u308b\u3053\u3068\u3092\u4e3b\u76ee\u7684\u3068\u3057\u305f\u5236\u5ea6\u3067\u3059\u30021\u4eba\u5e74\u959310\u4e07\u5186\u3092\u4e0a\u9650\u3068\u3057\u3001\u4e0a\u9577\u3067\u3042\u308b\u30c1\u30fc\u30e0\u30ea\u30fc\u30c0\u30fc\u304c\u627f\u8a8d\u3059\u308c\u3070\u3044\u308d\u3044\u308d\u306a\u4eba\u6750\u80b2\u6210\u65bd\u7b56\u3067\u4f7f\u7528\u53ef\u80fd\u306b\u3057\u3066\u3044\u307e\u3059\n\nSource: {'source': 'https:\/\/www.creationline.com\/tech-blog\/hr\/76913'}\nContent: \u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u306f\u300c\u53d7\u8b1b\u8cbb\u7528\u300d\u306b\u306e\u307f\u9069\u7528\n\u4ea4\u901a\u8cbb\u30fb\u5bbf\u6cca\u8cbb\u306f\u3001\u5225\u9014\u7d4c\u8cbb\u3068\u3057\u3066\u7533\u8acb\u53ef\u80fd\nSource: {'source': 'https:\/\/www.creationline.com\/tech-blog\/hr\/76913'}\nContent: \u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u3068\u306f\u3001\u30b9\u30ad\u30eb\u958b\u767a\u8cbb\u7528\u306e\u4e00\u90e8\u3092\u4f1a\u793e\u304c\u8ca0\u62c5\u3059\u308b\u3053\u3068\u3067\u3001\u30e1\u30f3\u30d0\u30fc\u306e\u7686\u3055\u3093\u306e\u30b9\u30ad\u30eb\u958b\u767a\u3092\u5968\u52b1\u3059\u308b\u3053\u3068\u3092\u4e3b\u76ee\u7684\u3068\u3057\u305f\u5236\u5ea6\u3067\u3059\u30021\u4eba\u5e74\u959310\u4e07\u5186\u3092\u4e0a\u9650\u3068\u3057\u3001\u4e0a\u9577\u3067\u3042\u308b\u30c1\u30fc\u30e0\u30ea\u30fc\u30c0\u30fc\u304c\u627f\u8a8d\u3059\u308c\u3070\u3044\u308d\u3044\u308d\u306a\u4eba\u6750\u80b2\u6210\u65bd\u7b56\u3067\u4f7f\u7528\u53ef\u80fd\u306b\u3057\u3066\u3044\u307e\u3059\n\nSource: {'source': 'https:\/\/www.creationline.com\/tech-blog\/hr\/76913'}\nContent: \u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u306f\u300c\u53d7\u8b1b\u8cbb\u7528\u300d\u306b\u306e\u307f\u9069\u7528\n\u4ea4\u901a\u8cbb\u30fb\u5bbf\u6cca\u8cbb\u306f\u3001\u5225\u9014\u7d4c\u8cbb\u3068\u3057\u3066\u7533\u8acb\u53ef\u80fd\n================================== Ai Message ==================================\n\n\u8cbb\u7528\u306e\u4e0a\u9650\u306f\u30011\u4eba\u5e74\u959310\u4e07\u5186\u3067\u3059\u3002<\/pre>\n\n\n\n<p>\u5fc5\u8981\u306a\u90e8\u5206\u3060\u3051\u629c\u304d\u51fa\u3059\u3068\u3001<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Q. \u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3\u306e\u300c\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u300d\u3068\u306f\uff1f<\/li>\n\n\n\n<li>A. \u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3\u306e\u300c\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u300d\u306f\u3001\u30e1\u30f3\u30d0\u30fc\u4e00\u4eba\u3072\u3068\u308a\u306e\u30b9\u30ad\u30eb\u5411\u4e0a\u3084\u30c1\u30e3\u30ec\u30f3\u30b8\u3092\u5f8c\u62bc\u3057\u3059\u308b\u305f\u3081\u306e\u5236\u5ea6\u3067\u3059\u30022024\u5e747\u6708\u304b\u3089\u30c8\u30e9\u30a4\u30a2\u30eb\u904b\u7528\u304c\u59cb\u307e\u308a\u3001\u30c8\u30e9\u30a4\u30a2\u30eb\u671f\u9593\u4e2d\u306b\u306f\u30ea\u30fc\u30c0\u30fc\u9663\u304c\u67d4\u8edf\u306b\u5bfe\u5fdc\u3057\u306a\u304c\u3089\u904b\u7528\u306e\u52b9\u679c\u3092\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u3002<\/li>\n\n\n\n<li>Q. \u8cbb\u7528\u306e\u4e0a\u9650\u306f\u3044\u304f\u3089\u3067\u3059\u304b\uff1f<\/li>\n\n\n\n<li>A. \u8cbb\u7528\u306e\u4e0a\u9650\u306f\u30011\u4eba\u5e74\u959310\u4e07\u5186\u3067\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3068\u306a\u308a\u307e\u3059\u3002\u300c<a href=\"https:\/\/www.creationline.com\/tech-blog\/76913\" target=\"_blank\" rel=\"noreferrer noopener\">\u307f\u3093\u306a\u3067\u80b2\u3080\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u30fb\u6b63\u5f0f\u5c0e\u5165\u3092\u6c7a\u5b9a\u3057\u307e\u3057\u305f<\/a>\u300d\u306b\u8a18\u8f09\u3055\u308c\u305f\u5185\u5bb9\u306b\u57fa\u3065\u3044\u3066\u56de\u7b54\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u5148\u306b\u30c1\u30e3\u30f3\u30af\u30b5\u30a4\u30ba\u3068\u30aa\u30fc\u30d0\u30fc\u30e9\u30c3\u30d7\u3092\u305d\u308c\u305e\u308c\u524d\u56de\u306e2\u500d\u306e\u5024\u306b\u3057\u305f\u3068\u66f8\u304d\u307e\u3057\u305f\u3002\u3068\u3044\u3046\u306e\u3082\u3001\u5143\u306e\u5024\u3060\u3068\u30d9\u30af\u30c8\u30eb\u691c\u7d22\u3067\u5f97\u3089\u308c\u305f\u30c1\u30e3\u30f3\u30af\u304c\u5c11\u306a\u304f\u3001\u8cbb\u7528\u306e\u60c5\u5831\u304c\u5f97\u3089\u308c\u306a\u304b\u3063\u305f\u305f\u3081\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u306a\u304a\u3001Tool Message\u304c\u30c0\u30d6\u3063\u3066\u8868\u793a\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u539f\u56e0\u306f\u3088\u304f\u308f\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u8cbb\u7528\u306e\u4e0a\u9650\u306f\u3044\u304f\u3089\u3067\u3059\u304b\uff1f\n================================== Ai Message ==================================\nTool Calls:\n  retrieve (call_N0fUwPtif0DCWo64fcmn748Y)\n Call ID: call_N0fUwPtif0DCWo64fcmn748Y\n  Args:\n    query: \u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3 \u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6 \u8cbb\u7528\u306e\u4e0a\u9650\n================================= Tool Message =================================\nName: retrieve\n\nSource: {'source': 'https:\/\/www.creationline.com\/tech-blog\/hr\/76913'}\nContent: \u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u306b\u3064\u3044\u3066\n\nSource: {'source': 'https:\/\/www.creationline.com\/tech-blog\/hr\/76913'}\nContent: \u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u3068\u306f\u3001\u30b9\u30ad\u30eb\u958b\u767a\u8cbb\u7528\u306e\u4e00\u90e8\u3092\u4f1a\u793e\u304c\u8ca0\u62c5\u3059\u308b\u3053\u3068\u3067\u3001\u30e1\u30f3\u30d0\u30fc\u306e\u7686\u3055\u3093\u306e\u30b9\u30ad\u30eb\u958b\u767a\u3092\u5968\u52b1\u3059\u308b\u3053\u3068\u3092\u4e3b\u76ee\u7684\u3068\u3057\u305f\u5236\u5ea6\u3067\u3059\nSource: {'source': 'https:\/\/www.creationline.com\/tech-blog\/hr\/76913'}\nContent: \u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u306b\u3064\u3044\u3066\n\nSource: {'source': 'https:\/\/www.creationline.com\/tech-blog\/hr\/76913'}\nContent: \u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u3068\u306f\u3001\u30b9\u30ad\u30eb\u958b\u767a\u8cbb\u7528\u306e\u4e00\u90e8\u3092\u4f1a\u793e\u304c\u8ca0\u62c5\u3059\u308b\u3053\u3068\u3067\u3001\u30e1\u30f3\u30d0\u30fc\u306e\u7686\u3055\u3093\u306e\u30b9\u30ad\u30eb\u958b\u767a\u3092\u5968\u52b1\u3059\u308b\u3053\u3068\u3092\u4e3b\u76ee\u7684\u3068\u3057\u305f\u5236\u5ea6\u3067\u3059\n================================== Ai Message ==================================\n\n\u305d\u306e\u60c5\u5831\u306f\u308f\u304b\u308a\u307e\u305b\u3093\u3002<\/pre>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306b\u3001\u540c\u3058\u8cea\u554f\u30fb\u540c\u3058\u30c7\u30fc\u30bf\u30bd\u30fc\u30b9\u3067\u3042\u3063\u3066\u3082\u3001\u30c1\u30e3\u30f3\u30af\u5316\uff08\u30c1\u30e3\u30f3\u30ad\u30f3\u30b0\uff09\u306e\u5024\u306b\u3088\u3063\u3066\u7d50\u679c\u304c\u5927\u304d\u304f\u5909\u308f\u3063\u3066\u3057\u307e\u3046\u305f\u3081\u3001\u3053\u306e\u8a2d\u5b9a\u306e\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u304c\u91cd\u8981\u306b\u306a\u308a\u307e\u3059\u3002\u5e83\u304f\u60c5\u5831\u3092\u30ab\u30d0\u30fc\u3059\u308b\u305f\u3081\u306b\u5927\u304d\u304f\u3059\u308b\u3068\u304b\u3048\u3063\u3066\u4e0d\u8981\u306a\u60c5\u5831\u307e\u3067\u5897\u3048\u3066\u3057\u307e\u3063\u305f\u308a\u3001\u751f\u6210AI\u306b\u6295\u5165\u3059\u308b\u30b3\u30b9\u30c8\u3082\u304b\u304b\u3063\u3066\u3057\u307e\u3046\u305f\u3081\u96e3\u3057\u3044\u3068\u3053\u308d\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5168\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># https:\/\/python.langchain.com\/docs\/tutorials\/qa_chat_history\/\n\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\n\nfrom langchain.chat_models import init_chat_model\n\nllm = init_chat_model(\n    model=os.getenv(\"AZURE_OPENAI_MODEL\"),\n    model_provider=\"azure_openai\",\n    azure_endpoint=os.getenv(\"AZURE_OPENAI_ENDPOINT\"),\n    api_key=os.getenv(\"AZURE_OPENAI_API_KEY\"),\n    api_version=os.getenv(\"AZURE_OPENAI_API_VERSION\"),\n)\n\nfrom langchain_openai import AzureOpenAIEmbeddings\n\nembeddings = AzureOpenAIEmbeddings(\n    model=os.getenv(\"AZURE_OPENAI_EMBEDDING_MODEL\"),\n    azure_endpoint=os.getenv(\"AZURE_OPENAI_ENDPOINT\"),\n    api_key=os.getenv(\"AZURE_OPENAI_API_KEY\"),\n    openai_api_version=os.getenv(\"AZURE_OPENAI_API_VERSION\"),\n)\n\nfrom langchain_core.vectorstores import InMemoryVectorStore\n\nvector_store = InMemoryVectorStore(embeddings)\n\nimport bs4\nfrom langchain_community.document_loaders import WebBaseLoader\n\nloader = WebBaseLoader(\n    web_paths=(\"https:\/\/www.creationline.com\/tech-blog\/hr\/76913\",),\n    bs_kwargs=dict(\n        parse_only=bs4.SoupStrainer(\n            class_=(\"content_post\", \"tech_header\")\n        )\n    ),\n)\ndocs = loader.load()\n\nfrom langchain_text_splitters import RecursiveCharacterTextSplitter\n\ntext_splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder(\n    separators=[\"\\n\\n\", \"\\n\", \"\u3002\"],\n    chunk_size=200, chunk_overlap=100\n)\nall_splits = text_splitter.split_documents(docs)\n\n_ = vector_store.add_documents(documents=all_splits)\n\n#-----\n\nfrom langgraph.graph import MessagesState, StateGraph\n\ngraph_builder = StateGraph(MessagesState)\n\n#-----\n\nfrom langchain_core.tools import tool\n\n@tool(response_format=\"content_and_artifact\")\ndef retrieve(query: str):\n    \"\"\"Retrieve information related to a query.\"\"\"\n    retrieved_docs = vector_store.similarity_search(query, k=2)\n    serialized = \"\\n\\n\".join(\n        (f\"Source: {doc.metadata}\\n\" f\"Content: {doc.page_content}\")\n        for doc in retrieved_docs\n    )\n    return serialized, retrieved_docs\n\n#-----\n\nfrom langchain_core.messages import SystemMessage\nfrom langgraph.prebuilt import ToolNode\n\ndef query_or_respond(state: MessagesState):\n    llm_with_tools = llm.bind_tools([retrieve])\n    response = llm_with_tools.invoke(state[\"messages\"])\n    return {\"messages\": [response]}\n\n#-----\n\ntools = ToolNode([retrieve])\n\n#-----\n\ndef generate(state: MessagesState):\n    recent_tool_messages = []\n    for message in reversed(state[\"messages\"]):\n        if message.type == \"tool\":\n            recent_tool_messages.append(message)\n        else:\n            break\n    tool_messages = recent_tool_messages[::-1]\n\n#-----\n\n    docs_content = \"\\n\\n\".join(doc.content for doc in tool_messages)\n    print(docs_content)\n    system_message_content = (\n        \"You are an assistant for question-answering tasks. \"\n        \"Use the following pieces of retrieved context to answer \"\n        \"the question. If you don't know the answer, say that you \"\n        \"don't know. Use three sentences maximum and keep the \"\n        \"answer concise.\"\n        \"\\n\\n\"\n        f\"{docs_content}\"\n    )\n\n#-----\n\n    conversation_messages = [\n        message\n        for message in state[\"messages\"]\n        if message.type in (\"human\", \"system\")\n        or (message.type == \"ai\" and not message.tool_calls)\n    ]\n    prompt = [SystemMessage(system_message_content)] + conversation_messages\n\n#-----\n\n    response = llm.invoke(prompt)\n    return {\"messages\": [response]}\n\n#-----\n\nfrom langgraph.graph import END\nfrom langgraph.prebuilt import ToolNode, tools_condition\n\ngraph_builder.add_node(query_or_respond)\ngraph_builder.add_node(tools)\ngraph_builder.add_node(generate)\n\ngraph_builder.set_entry_point(\"query_or_respond\")\ngraph_builder.add_conditional_edges(\n    \"query_or_respond\",\n    tools_condition,\n    {END: END, \"tools\": \"tools\"},\n)\ngraph_builder.add_edge(\"tools\", \"generate\")\ngraph_builder.add_edge(\"generate\", END)\n\n#-----\n\nfrom langgraph.checkpoint.memory import MemorySaver\n\nmemory = MemorySaver()\ngraph = graph_builder.compile(checkpointer=memory)\n\nconfig = {\"configurable\": {\"thread_id\": \"abc123\"}}\n\n#-----\n\ninput_messages = [\n    \"\u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3\u306e\u300c\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u300d\u3068\u306f\uff1f\",\n    \"\u8cbb\u7528\u306e\u4e0a\u9650\u306f\u3044\u304f\u3089\u3067\u3059\u304b\uff1f\",\n]\n\nfor input_message in input_messages:\n    for step in graph.stream(\n        {\"messages\": [{\"role\": \"user\", \"content\": input_message}]},\n        stream_mode=\"values\",\n        config=config,\n    ):\n        step[\"messages\"][-1].pretty_print()<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u672c\u7a3f\u3067\u306f <a href=\"https:\/\/www.langchain.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">LangChain<\/a> \u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb <a href=\"https:\/\/python.langchain.com\/docs\/tutorials\/qa_chat_history\/\" target=\"_blank\" rel=\"noreferrer noopener\">Build a Retrieval Augmented Generation (RAG) App: Part 2<\/a> \u3092 <a href=\"https:\/\/azure.microsoft.com\/ja-jp\/products\/ai-services\/openai-service\" target=\"_blank\" rel=\"noreferrer noopener\">Azure OpenAI<\/a> \u3092\u4f7f\u3063\u3066\u5b9f\u65bd\u3057\u3066\u307f\u305f\u8a18\u9332\u3067\u3059\u3002\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306e\u5185\u5bb9\u3092\u305d\u306e\u307e\u307e\u4f7f\u3046\u306e\u3067\u306f\u306a\u304f\u3001\u5f0a\u793e Tech blog \u306e\u8a18\u4e8b\u300c<a href=\"https:\/\/www.creationline.com\/tech-blog\/76913\" target=\"_blank\" rel=\"noreferrer noopener\">\u307f\u3093\u306a\u3067\u80b2\u3080\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u30fb\u6b63\u5f0f\u5c0e\u5165\u3092\u6c7a\u5b9a\u3057\u307e\u3057\u305f<\/a>\u300d\u306b\u8a18\u8f09\u3055\u308c\u305f\u5185\u5bb9\u306b\u57fa\u3065\u3044\u3066\u3001\u300c\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u652f\u63f4\u5236\u5ea6\u300d\u306b\u3064\u3044\u3066\u7d99\u7d9a\u7684\u306a\u8cea\u7591\u5fdc\u7b54\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u306f\u56fa\u5b9a\u306e\u8cea\u554f\u3067\u3057\u305f\u304c\u3001\u904e\u53bb\u8a18\u4e8b\u300c<a href=\"https:\/\/www.creationline.com\/tech-blog\/75785\" target=\"_blank\" rel=\"noreferrer noopener\">LangGraph\u306e\u4f1a\u8a71\u5c65\u6b74\u3092\u30e1\u30e2\u30ea\u4fdd\u6301\u3057\u3088\u3046<\/a>\u300d\u300c<a href=\"https:\/\/www.creationline.com\/tech-blog\/75797\" target=\"_blank\" rel=\"noreferrer noopener\">LangGraph\u306e\u4f1a\u8a71\u5c65\u6b74\u3092SQLite\u306b\u4fdd\u6301\u3057\u3088\u3046<\/a>\u300d\u3092\u53c2\u7167\u3059\u308c\u3070\u3001\u8cea\u554f\u3092\u81ea\u7531\u306b\u5165\u529b\u3067\u304d\u308b\u3088\u3046\u306b\u6539\u826f\u3059\u308b\u306e\u306f\u5bb9\u6613\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u672c\u7a3f\u3067\u306f\u3001\u30c1\u30e3\u30f3\u30af\u5316\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u3088\u3063\u3066\u30d9\u30af\u30c8\u30eb\u691c\u7d22\u7d50\u679c\u304c\u5de6\u53f3\u3055\u308c\u308b\u3053\u3068\u3082\u898b\u3066\u307f\u307e\u3057\u305f\u3002\u56de\u7b54\u306e\u78ba\u304b\u3089\u3057\u3055\u3092\u5411\u4e0a\u3055\u305b\u308b\u305f\u3081\u306b\u306f\u3001\u8a2d\u5b9a\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u3068\u30c6\u30b9\u30c8\u304c\u91cd\u8981\u306b\u306a\u308b\u3068\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u672c\u30d6\u30ed\u30b0\u3067\u306f\u5f15\u304d\u7d9a\u304d\u751f\u6210AI\u306b\u3088\u308b\u4f1a\u8a71\u7cbe\u5ea6\u5411\u4e0a\u3084\u6a5f\u80fd\u306b\u3064\u3044\u3066\u53d6\u308a\u4e0a\u3052\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b \u672c\u7a3f\u3067\u306f LangChain \u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb Build a Retrieval Augmented Generation (RAG) App: Part 2 \u3092 Azure OpenAI \u3092\u4f7f\u3063\u3066\u5b9f\u65bd\u3057\u3066\u307f [&#8230;]<\/p>\n","protected":false},"author":2,"featured_media":77104,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[779,58,817,31,1004,323],"tags":[],"class_list":["post-77047","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","category-azure","category-chatgpt-ai","category-higuchi","category-llm","category-python"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>LangChain\u306eRAG\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u3084\u3063\u3066\u307f\u305f\uff08\u5f8c\u7de8\uff09 #langchain #langgraph #rag #azure #openai - Tech Blog\uff5c\u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3<\/title>\n<meta name=\"description\" content=\"AI, Azure, ChatGPT\uff06AI, d-higuchi, LLM, Python |\u306f\u3058\u3081\u306b \u672c\u7a3f\u3067\u306f LangChain \u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb Build a Retrieval Augmented Generation (RAG) App:\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LangChain\u306eRAG\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u3084\u3063\u3066\u307f\u305f\uff08\u5f8c\u7de8\uff09 #langchain #langgraph #rag #azure #openai - Tech Blog\uff5c\u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3\" \/>\n<meta property=\"og:description\" content=\"AI, Azure, ChatGPT\uff06AI, d-higuchi, LLM, Python |\u306f\u3058\u3081\u306b \u672c\u7a3f\u3067\u306f LangChain \u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb Build a Retrieval Augmented Generation (RAG) App:\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047\" \/>\n<meta property=\"og:site_name\" content=\"Tech Blog\uff5c\u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/creationline\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-17T23:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2025\/04\/rag_retrieval_generation-1046_part2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"844\" \/>\n\t<meta property=\"og:image:height\" content=\"433\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Daisuke Higuchi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@creationline\" \/>\n<meta name=\"twitter:site\" content=\"@creationline\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"Daisuke Higuchi\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"7\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047\"},\"author\":{\"name\":\"Daisuke Higuchi\",\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/#\/schema\/person\/16f1373831fb6fd17387f16ae1195206\"},\"headline\":\"LangChain\u306eRAG\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u3084\u3063\u3066\u307f\u305f\uff08\u5f8c\u7de8\uff09 #langchain #langgraph #rag #azure #openai\",\"datePublished\":\"2025-04-17T23:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047\"},\"wordCount\":119,\"image\":{\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2025\/04\/rag_retrieval_generation-1046_part2.png\",\"articleSection\":[\"AI\",\"Azure\",\"ChatGPT\uff06AI\",\"d-higuchi\",\"LLM\",\"Python\"],\"inLanguage\":\"ja\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047\",\"url\":\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047\",\"name\":\"LangChain\u306eRAG\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u3084\u3063\u3066\u307f\u305f\uff08\u5f8c\u7de8\uff09 #langchain #langgraph #rag #azure #openai - Tech Blog\uff5c\u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3\",\"isPartOf\":{\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2025\/04\/rag_retrieval_generation-1046_part2.png\",\"datePublished\":\"2025-04-17T23:00:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/#\/schema\/person\/16f1373831fb6fd17387f16ae1195206\"},\"description\":\"AI, Azure, ChatGPT\uff06AI, d-higuchi, LLM, Python |\u306f\u3058\u3081\u306b \u672c\u7a3f\u3067\u306f LangChain \u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb Build a Retrieval Augmented Generation (RAG) App:\",\"breadcrumb\":{\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047#primaryimage\",\"url\":\"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2025\/04\/rag_retrieval_generation-1046_part2.png\",\"contentUrl\":\"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2025\/04\/rag_retrieval_generation-1046_part2.png\",\"width\":844,\"height\":433},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"HOME\",\"item\":\"https:\/\/www.creationline.com\/tech-blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ChatGPT\uff06AI\",\"item\":\"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"LangChain\u306eRAG\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u3084\u3063\u3066\u307f\u305f\uff08\u5f8c\u7de8\uff09 #langchain #langgraph #rag #azure #openai\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/#website\",\"url\":\"https:\/\/www.creationline.com\/tech-blog\/\",\"name\":\"Tech Blog\uff5c\u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3\",\"description\":\"\u30a2\u30b8\u30e3\u30a4\u30eb\uff06DevOps\u3001\u30af\u30e9\u30a6\u30c9\u30cd\u30a4\u30c6\u30a3\u30d6\u3001AI\uff06LLM\u306e\u5148\u7aef\u6280\u8853\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.creationline.com\/tech-blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ja\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/#\/schema\/person\/16f1373831fb6fd17387f16ae1195206\",\"name\":\"Daisuke Higuchi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2023\/08\/d-higuchi-wp-icon-230x230.png\",\"url\":\"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2023\/08\/d-higuchi-wp-icon-230x230.png\",\"contentUrl\":\"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2023\/08\/d-higuchi-wp-icon-230x230.png\",\"caption\":\"Daisuke Higuchi\"},\"description\":\"Chef\u30fbDocker\u30fbMirantis\u88fd\u54c1\u306a\u3069\u306e\u6280\u8853\u8981\u7d20\u306b\u52a0\u3048\u3066\u3001\u4f1a\u8b70\u306e\u9032\u3081\u65b9\u30fb\u6587\u7ae0\u306e\u66f8\u304d\u65b9\u306a\u3069\u306e\u696d\u52d9\u6539\u5584\u306b\u3082\u53d6\u308a\u7d44\u3093\u3067\u3044\u307e\u3059\u3002\u300cChef\u6d3b\u7528\u30ac\u30a4\u30c9\u300d\u5171\u8457\u306e\u307b\u304b\u3001Debian Official Developer\u3082\u3084\u3063\u3066\u3044\u307e\u3059\u3002\",\"url\":\"https:\/\/www.creationline.com\/tech-blog\/author\/higuchi\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"LangChain\u306eRAG\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u3084\u3063\u3066\u307f\u305f\uff08\u5f8c\u7de8\uff09 #langchain #langgraph #rag #azure #openai - Tech Blog\uff5c\u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3","description":"AI, Azure, ChatGPT\uff06AI, d-higuchi, LLM, Python |\u306f\u3058\u3081\u306b \u672c\u7a3f\u3067\u306f LangChain \u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb Build a Retrieval Augmented Generation (RAG) App:","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047","og_locale":"ja_JP","og_type":"article","og_title":"LangChain\u306eRAG\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u3084\u3063\u3066\u307f\u305f\uff08\u5f8c\u7de8\uff09 #langchain #langgraph #rag #azure #openai - Tech Blog\uff5c\u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3","og_description":"AI, Azure, ChatGPT\uff06AI, d-higuchi, LLM, Python |\u306f\u3058\u3081\u306b \u672c\u7a3f\u3067\u306f LangChain \u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb Build a Retrieval Augmented Generation (RAG) App:","og_url":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047","og_site_name":"Tech Blog\uff5c\u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3","article_publisher":"https:\/\/www.facebook.com\/creationline","article_published_time":"2025-04-17T23:00:00+00:00","og_image":[{"width":844,"height":433,"url":"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2025\/04\/rag_retrieval_generation-1046_part2.png","type":"image\/png"}],"author":"Daisuke Higuchi","twitter_card":"summary_large_image","twitter_creator":"@creationline","twitter_site":"@creationline","twitter_misc":{"\u57f7\u7b46\u8005":"Daisuke Higuchi","\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593":"7\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047#article","isPartOf":{"@id":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047"},"author":{"name":"Daisuke Higuchi","@id":"https:\/\/www.creationline.com\/tech-blog\/#\/schema\/person\/16f1373831fb6fd17387f16ae1195206"},"headline":"LangChain\u306eRAG\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u3084\u3063\u3066\u307f\u305f\uff08\u5f8c\u7de8\uff09 #langchain #langgraph #rag #azure #openai","datePublished":"2025-04-17T23:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047"},"wordCount":119,"image":{"@id":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047#primaryimage"},"thumbnailUrl":"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2025\/04\/rag_retrieval_generation-1046_part2.png","articleSection":["AI","Azure","ChatGPT\uff06AI","d-higuchi","LLM","Python"],"inLanguage":"ja"},{"@type":"WebPage","@id":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047","url":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047","name":"LangChain\u306eRAG\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u3084\u3063\u3066\u307f\u305f\uff08\u5f8c\u7de8\uff09 #langchain #langgraph #rag #azure #openai - Tech Blog\uff5c\u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3","isPartOf":{"@id":"https:\/\/www.creationline.com\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047#primaryimage"},"image":{"@id":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047#primaryimage"},"thumbnailUrl":"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2025\/04\/rag_retrieval_generation-1046_part2.png","datePublished":"2025-04-17T23:00:00+00:00","author":{"@id":"https:\/\/www.creationline.com\/tech-blog\/#\/schema\/person\/16f1373831fb6fd17387f16ae1195206"},"description":"AI, Azure, ChatGPT\uff06AI, d-higuchi, LLM, Python |\u306f\u3058\u3081\u306b \u672c\u7a3f\u3067\u306f LangChain \u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb Build a Retrieval Augmented Generation (RAG) App:","breadcrumb":{"@id":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047"]}]},{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047#primaryimage","url":"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2025\/04\/rag_retrieval_generation-1046_part2.png","contentUrl":"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2025\/04\/rag_retrieval_generation-1046_part2.png","width":844,"height":433},{"@type":"BreadcrumbList","@id":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai\/77047#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"HOME","item":"https:\/\/www.creationline.com\/tech-blog"},{"@type":"ListItem","position":2,"name":"ChatGPT\uff06AI","item":"https:\/\/www.creationline.com\/tech-blog\/chatgpt-ai"},{"@type":"ListItem","position":3,"name":"LangChain\u306eRAG\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u3084\u3063\u3066\u307f\u305f\uff08\u5f8c\u7de8\uff09 #langchain #langgraph #rag #azure #openai"}]},{"@type":"WebSite","@id":"https:\/\/www.creationline.com\/tech-blog\/#website","url":"https:\/\/www.creationline.com\/tech-blog\/","name":"Tech Blog\uff5c\u30af\u30ea\u30a8\u30fc\u30b7\u30e7\u30f3\u30e9\u30a4\u30f3","description":"\u30a2\u30b8\u30e3\u30a4\u30eb\uff06DevOps\u3001\u30af\u30e9\u30a6\u30c9\u30cd\u30a4\u30c6\u30a3\u30d6\u3001AI\uff06LLM\u306e\u5148\u7aef\u6280\u8853","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.creationline.com\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ja"},{"@type":"Person","@id":"https:\/\/www.creationline.com\/tech-blog\/#\/schema\/person\/16f1373831fb6fd17387f16ae1195206","name":"Daisuke Higuchi","image":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2023\/08\/d-higuchi-wp-icon-230x230.png","url":"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2023\/08\/d-higuchi-wp-icon-230x230.png","contentUrl":"https:\/\/www.creationline.com\/tech-blog\/cms_x3GWkuX\/wp-content\/uploads\/2023\/08\/d-higuchi-wp-icon-230x230.png","caption":"Daisuke Higuchi"},"description":"Chef\u30fbDocker\u30fbMirantis\u88fd\u54c1\u306a\u3069\u306e\u6280\u8853\u8981\u7d20\u306b\u52a0\u3048\u3066\u3001\u4f1a\u8b70\u306e\u9032\u3081\u65b9\u30fb\u6587\u7ae0\u306e\u66f8\u304d\u65b9\u306a\u3069\u306e\u696d\u52d9\u6539\u5584\u306b\u3082\u53d6\u308a\u7d44\u3093\u3067\u3044\u307e\u3059\u3002\u300cChef\u6d3b\u7528\u30ac\u30a4\u30c9\u300d\u5171\u8457\u306e\u307b\u304b\u3001Debian Official Developer\u3082\u3084\u3063\u3066\u3044\u307e\u3059\u3002","url":"https:\/\/www.creationline.com\/tech-blog\/author\/higuchi"}]}},"_links":{"self":[{"href":"https:\/\/www.creationline.com\/tech-blog\/wp-json\/wp\/v2\/posts\/77047","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.creationline.com\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.creationline.com\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.creationline.com\/tech-blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.creationline.com\/tech-blog\/wp-json\/wp\/v2\/comments?post=77047"}],"version-history":[{"count":2,"href":"https:\/\/www.creationline.com\/tech-blog\/wp-json\/wp\/v2\/posts\/77047\/revisions"}],"predecessor-version":[{"id":77103,"href":"https:\/\/www.creationline.com\/tech-blog\/wp-json\/wp\/v2\/posts\/77047\/revisions\/77103"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.creationline.com\/tech-blog\/wp-json\/wp\/v2\/media\/77104"}],"wp:attachment":[{"href":"https:\/\/www.creationline.com\/tech-blog\/wp-json\/wp\/v2\/media?parent=77047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.creationline.com\/tech-blog\/wp-json\/wp\/v2\/categories?post=77047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.creationline.com\/tech-blog\/wp-json\/wp\/v2\/tags?post=77047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}