<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title><![CDATA[Neha Saini - Elasticsearch Labs]]></title>
    <description><![CDATA[Articles and tutorials from the Search team at Elastic]]></description>
    <copyright><![CDATA[© 2026. Elasticsearch B.V. All Rights Reserved]]></copyright>
    <image>
      <title><![CDATA[Neha Saini - Elasticsearch Labs]]></title>
      <url>https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt1121c0bf0e8a6e65/6a88da6340a1841030ef456f/search-labs-thumbnail.png</url>
      <link>https://www.elastic.co/jp/search-labs/author/neha-saini</link>
    </image>
    <link>https://www.elastic.co/jp/search-labs/author/neha-saini</link>
    <atom:link href="https://www.elastic.co/jp/search-labs/rss/author/neha-saini.xml" rel="self" type="application/rss+xml"/>
    <language><![CDATA[jp]]></language>
    <lastBuildDate>Mon, 28 Sep 2026 12:48:14 GMT</lastBuildDate>
  <item>
    <title><![CDATA[LangGraphとElasticsearchを使用したRAGワークフローの構築]]></title>
    <description><![CDATA[Elasticsearch を使用して LangGraph 検索エージェント テンプレートを構成およびカスタマイズし、効率的なデータ取得と AI 駆動型応答のための RAG ワークフローを構築する方法を学習します。]]></description>
    <content:encoded><![CDATA[<p><a href="https://github.com/langchain-ai/retrieval-agent-template">LangGraph 検索エージェント テンプレートは、</a> LangGraph Studio で LangGraph を使用して検索ベースの質問応答システムの作成を容易にするために LangChain によって開発されたスターター プロジェクトです。このテンプレートは Elasticsearch とシームレスに統合するように事前構成されているため、開発者はドキュメントを効率的にインデックスして取得できるエージェントを迅速に構築できます。</p><p>このブログでは、LangGraph Studio と LangGraph CLI を使用して LangChain 検索エージェント テンプレートを実行およびカスタマイズすることに焦点を当てています。このテンプレートは、Elasticsearch などのさまざまな検索バックエンドを活用して、検索拡張生成 (RAG) アプリケーションを構築するためのフレームワークを提供します。</p><p>エージェントフローをカスタマイズしながら、Elastic を使用してテンプレートを効率的にセットアップ、環境の構成、実行する方法を説明します。</p><h2>要件</h2><p>続行する前に、以下がインストールされていることを確認してください。</p><ul><li><p>Elasticsearch Cloud デプロイメントまたはオンプレミス Elasticsearch デプロイメント (または Elastic Cloud で 14 日間の<a href="https://www.elastic.co/jp/cloud/cloud-trial-overview">無料トライアル</a>を作成) - バージョン 8.0.0 以上</p></li><li><p>Python 3.9以上</p></li><li><p><a href="https://cohere.com/">Cohere</a> （このガイドで使用）、 <a href="https://openai.com/">OpenAI</a> 、 <a href="https://www.anthropic.com/claude">Anthropic/Claude</a>などのLLMプロバイダーへのアクセス</p></li></ul><h2>LangGraphアプリの作成</h2><h3>1. LangGraph CLIをインストールする</h3>pip install --upgrade "langgraph-cli[inmem]"<h3>2. 検索エージェントテンプレートからLangGraphアプリを作成する</h3>mkdir lg-agent-demo
cd lg-agent-demo
langgraph new lg-agent-demo <p><em>利用可能なテンプレートのリストから選択できるインタラクティブ メニューが表示されます。</em>以下に示すように、取得エージェントの場合は 4、Python の場合は 1 を選択します。</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltd44177037ea46d45/6a17f86b3e9e45265fba1663/6a41a41f95c2477c67810adc7be46d91faf06878-1600x407.png" alt="インタラクティブな検索テンプレート。" /><ul><li><p><strong>トラブルシューティング</strong>: 「urllib.error.URLError: &lt;urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: cannot get local issuer certificate (_ssl.c:1000)&gt;」というエラーが発生した場合「</p></li></ul><p>問題を解決するには、以下に示すように、Python の証明書インストール コマンドを実行してください。</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltbbe2d1d3a1af75b1/6a17f86d445de97c9c4d02e7/83ec238136c41738457299fd42c83aff32eb5b97-1407x75.png" alt="Python の証明書インストール コマンドを実行します。" /><h3>3. 依存関係をインストールする</h3><p>新しい LangGraph アプリのルートで仮想環境を作成し、依存関係を<code>edit</code>モードでインストールして、ローカルの変更がサーバーで使用されるようにします。</p>#For Mac
python3 -m venv lg-demo
source lg-demo/bin/activate 
pip install -e .

#For Windows
python3 -m venv lg-demo
lg-demo\Scripts\activate 
pip install -e .<h2>環境の設定</h2><h3>1. .environmentを作成するファイル</h3><p><code>.env</code>ファイルには、アプリが選択した LLM および取得プロバイダーに接続できるようにするための API キーと構成が保持されます。サンプル設定を複製して新しい<code>.env</code>ファイルを生成します。</p>cp .env.example .env<h3>2. .envを設定するファイル</h3><p><code>.env</code>ファイルには、デフォルトの構成のセットが付属しています。設定に応じて必要な API キーと値を追加することで更新できます。ユースケースに関係のないキーは、変更せずにそのままにしておくことも、削除することもできます。</p># To separate your traces from other applications
LANGSMITH_PROJECT=retrieval-agent

# LLM choice (set the API key for your selected provider):
ANTHROPIC_API_KEY=your_anthropic_api_key
FIREWORKS_API_KEY=your_fireworks_api_key
OPENAI_API_KEY=your_openai_api_key

# Retrieval provider (configure based on your chosen service):

## Elastic Cloud:
ELASTICSEARCH_URL=https://your_elastic_cloud_url
ELASTICSEARCH_API_KEY=your_elastic_api_key

## Elastic Local:
ELASTICSEARCH_URL=http://host.docker.internal:9200
ELASTICSEARCH_USER=elastic
ELASTICSEARCH_PASSWORD=changeme

## Pinecone:
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_INDEX_NAME=your_pinecone_index_name

## MongoDB Atlas:
MONGODB_URI=your_mongodb_connection_string

# Cohere API key:
COHERE_API_KEY=your_cohere_api_key<ul><li><p>サンプル<code>.env</code>ファイル (Elastic Cloud と Cohere を使用)</p></li></ul><p>以下は、このブログで説明されているように、 <strong>Elastic Cloud を</strong>取得プロバイダーとして使用し、 <strong>Cohere を</strong>LLM として使用するためのサンプルの<code>.env</code>構成です。</p># To separate your traces from other applications
LANGSMITH_PROJECT=retrieval-agent
#Retrieval Provider
# Elasticsearch configuration
ELASTICSEARCH_URL=elastic-url:443
ELASTICSEARCH_API_KEY=elastic_api_key
# Cohere API key
COHERE_API_KEY=cohere_api_key<p><em>注: このガイドでは、レスポンス生成と埋め込みの両方にCohereを使用していますが、ユースケースに応じて、</em><em><strong> OpenAI</strong></em><em> 、</em><em><strong> Claude</strong></em><em> 、あるいはローカルLLMモデル などの他のLLMプロバイダーも自由に使用できます 。使用する予定の各キーが</em><em><code>.env</code></em><em> ファイル に存在し、正しく設定されていることを確認してください。</em></p><h3>3. 設定ファイル -configuration.py を更新する </h3><p>適切な API キーを使用して<code>.env</code>ファイルを設定したら、次の手順ではアプリケーションのデフォルトのモデル構成を更新します。構成を更新すると、システムは<code>.env</code>ファイルで指定したサービスとモデルを使用するようになります。</p><p>構成ファイルに移動します。</p> cd src/retrieval_graph<p><code>configuration.py</code>ファイルには、検索エージェントが 3 つの主なタスクに使用するデフォルトのモデル設定が含まれています。</p><ul><li><p><strong>埋め込みモデル</strong>– ドキュメントをベクトル表現に変換する</p></li><li><p><strong>クエリモデル</strong>– ユーザーのクエリをベクトルに変換する</p></li><li><p><strong>レスポンスモデル</strong>– 最終的なレスポンスを生成する</p></li></ul><p>デフォルトでは、コードは<strong>OpenAI</strong> (例: <code>openai/text-embedding-3-small</code> ) と<strong>Anthropic</strong> (例: <code>anthropic/claude-3-5-sonnet-20240620 and anthropic/claude-3-haiku-20240307</code> ) のモデルを使用します。このブログでは、Cohere モデルの使用に切り替えます。すでに OpenAI または Anthropic を使用している場合は、変更は必要ありません。</p><h4>変更例（Cohere を使用）:</h4><p><code>configuration.py</code>を開き、以下のようにモデルのデフォルトを変更します。</p>…
 embedding_model: Annotated[
       str,
       {"__template_metadata__": {"kind": "embeddings"}},
   ] = field(
       default="cohere/embed-english-v3.0",
…
response_model: Annotated[str, {"__template_metadata__": {"kind": "llm"}}] = field(
       default="cohere/command-r-08-2024",
…
query_model: Annotated[str, {"__template_metadata__": {"kind": "llm"}}] = field(
       default="cohere/command-r-08-2024",
       metadata={<h2>LangGraph CLI で取得エージェントを実行する</h2><h3>1. LangGraphサーバーを起動する</h3>cd lg-agent-demo
langgraph dev<p>これにより、LangGraph API サーバーがローカルで起動します。これが正常に実行されると、次のような画面が表示されます。</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt46c7a703e715ef66/6a17f86eb1e113272d79f42e/e3c3344b24651067e2d0892d870feca505b3be35-1494x542.png" alt=" LangGraph API サーバーが正常に実行されています。" /><p>Studio UI URL を開きます。</p><p>利用可能なグラフは 2 つあります。</p><ul><li><p><strong>取得グラフ</strong>: Elasticsearch からデータを取得し、LLM を使用してクエリに応答します。</p></li><li><p><strong>インデクサー グラフ</strong>: ドキュメントを Elasticsearch にインデックスし、LLM を使用して埋め込みを生成します。</p></li></ul><h3>2. インデクサーグラフの設定</h3><ul><li><p>インデクサー グラフを開きます。</p></li><li><p>アシスタントの管理をクリックします。</p><ul><li><p><strong>「新しいアシスタントを追加</strong>」をクリックし、指定どおりにユーザーの詳細を入力して、ウィンドウを閉じます。</p></li></ul></li></ul>{"user_id": "101"}<h3>3. サンプル文書のインデックス作成</h3><ul><li><p>NoveTech という組織の仮想的な四半期レポートを表す次のサンプル ドキュメントにインデックスを付けます。</p></li></ul>[
  {    "page_content": "NoveTech Solutions Q1 2025 Report - Revenue: $120.5M, Net Profit: $18.2M, EPS: $2.15. Strong AI software launch and $50M government contract secured."
  },
  {
    "page_content": "NoveTech Solutions Business Highlights - AI-driven analytics software gained 15% market share. Expansion into Southeast Asia with two new offices. Cloud security contract secured."
  },
  {
    "page_content": "NoveTech Solutions Financial Overview - Operating expenses at $85.3M, Gross Margin 29.3%. Stock price rose from $72.5 to $78.3. Market Cap reached $5.2B."
  },
  {
    "page_content": "NoveTech Solutions Challenges - Rising supply chain costs impacting hardware production. Regulatory delays slowing European expansion. Competitive pressure in cybersecurity sector."
  },
  {
    "page_content": "NoveTech Solutions Future Outlook - Expected revenue for Q2 2025: $135M. New AI chatbot and blockchain security platform launch planned. Expansion into Latin America."
  },
  {
    "page_content": "NoveTech Solutions Market Performance - Year-over-Year growth at 12.7%. Stock price increase reflects investor confidence. Cybersecurity and AI sectors remain competitive."
  },
  {
    "page_content": "NoveTech Solutions Strategic Moves - Investing in R&amp;D to enhance AI-driven automation. Strengthening partnerships with enterprise cloud providers. Focusing on data privacy solutions."
  },
  {
    "page_content": "NoveTech Solutions CEO Statement - 'NoveTech Solutions continues to innovate in AI and cybersecurity. Our growth strategy remains strong, and we foresee steady expansion in the coming quarters.'"
  }
]<p>ドキュメントがインデックスされると、以下に示すように、スレッドに削除メッセージが表示されます。</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt38715eadffcb62f0/6a17f877faa9135f7393ca4c/fd3a1efd64cb54d54ea56ef5055249dd066d5708-1600x854.png" alt="LangGraph および Elasticsearch RAG ワークフロー ドキュメントがインデックス化されました。" /><h3>4. 検索グラフの実行</h3><ul><li><p>検索グラフに切り替えます。</p></li><li><p>次の検索クエリを入力してください。</p></li></ul>What was NovaTech Solutions total revenue in Q1 2025?<img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt5c0d070fca52e512/6a17f879505ac36d37ad8d12/eb4d8ddfe0effd7e1868fba921b8ef13f7baf27a-1600x755.png" alt="LangGraphとElasticsearchの検索グラフを実行する" /><p>システムは関連するドキュメントを返し、インデックスされたデータに基づいて正確な回答を提供します。</p><h2>検索エージェントをカスタマイズする</h2><p>ユーザー エクスペリエンスを向上させるために、検索グラフにカスタマイズ ステップを導入し、ユーザーが次に尋ねる可能性のある 3 つの質問を予測します。この予測は以下に基づいています:</p><ul><li><p>取得した文書のコンテキスト</p></li><li><p>以前のユーザーインタラクション</p></li><li><p>最後のユーザークエリ</p></li></ul><p>クエリ予測機能を実装するには、次のコード変更が必要です。</p><h3>1. graph.pyを更新する</h3><ul><li><p><code>predict_query</code>関数を追加します:</p></li></ul>async def predict_query(
   state: State, *, config: RunnableConfig
) -&gt; dict[str, list[BaseMessage]]:
   logger.info(f"predict_query predict_querypredict_query predict_query predict_query predict_query")  # Log the query

   configuration = Configuration.from_runnable_config(config)
   prompt = ChatPromptTemplate.from_messages(
       [
           ("system", configuration.predict_next_question_prompt),
           ("placeholder", "{messages}"),
       ]
   )
   model = load_chat_model(configuration.response_model)
   user_query = state.queries[-1] if state.queries else "No prior query available"
   logger.info(f"user_query: {user_query}")
   logger.info(f"statemessage: {state.messages}")
   #human_messages = [msg for msg in state.message if isinstance(msg, HumanMessage)]

   message_value = await prompt.ainvoke(
       {
           "messages": state.messages,
           "user_query": user_query,  # Use the most recent query as primary input
           "system_time": datetime.now(tz=timezone.utc).isoformat(),
       },
       config,
   )

   next_question = await model.ainvoke(message_value, config)
   return {"next_question": [next_question]}<ul><li><p><code>respond</code>関数を変更して、メッセージの代わりに<strong><code>response</code></strong>オブジェクトを返します。</p></li></ul>async def respond(
   state: State, *, config: RunnableConfig
) -&gt; dict[str, list[BaseMessage]]:
   """Call the LLM powering our "agent"."""
   configuration = Configuration.from_runnable_config(config)
   # Feel free to customize the prompt, model, and other logic!
   prompt = ChatPromptTemplate.from_messages(
       [
           ("system", configuration.response_system_prompt),
           ("placeholder", "{messages}"),
       ]
   )
   model = load_chat_model(configuration.response_model)

   retrieved_docs = format_docs(state.retrieved_docs)
   message_value = await prompt.ainvoke(
       {
           "messages": state.messages,
           "retrieved_docs": retrieved_docs,
           "system_time": datetime.now(tz=timezone.utc).isoformat(),
       },
       config,
   )
   response = await model.ainvoke(message_value, config)
   # We return a list, because this will get added to the existing list
   return {"response": [response]}<ul><li><p>グラフ構造を更新して、predict_query に新しいノードとエッジを追加します。</p></li></ul>builder.add_node(generate_query)
builder.add_node(retrieve)
builder.add_node(respond)
builder.add_node(predict_query)
builder.add_edge("__start__", "generate_query")
builder.add_edge("generate_query", "retrieve")
builder.add_edge("retrieve", "respond")
builder.add_edge("respond", "predict_query")<h3>2. prompts.pyを更新する</h3><ul><li><p><code>prompts.py</code>でのクエリ予測のプロンプトを作成します:</p></li></ul>PREDICT_NEXT_QUESTION_PROMPT = """Given the user query and the retrieved documents, suggest the most likely next question the user might ask.

**Context:**
- Previous Queries:
{previous_queries}

- Latest User Query: {user_query}

- Retrieved Documents:
{retrieved_docs}

**Guidelines:**
1. Do not suggest a question that has already been asked in previous queries.
2. Consider the retrieved documents when predicting the next logical question.
3. If the user's query is already fully answered, suggest a relevant follow-up question.
4. Keep the suggested question natural and conversational.
5. Suggest at least 3 question

System time: {system_time}"""<h3>3. configuration.pyを更新する</h3><ul><li><p><code>predict_next_question_prompt</code>追加:</p></li></ul>predict_next_question_prompt: str = field(
       default=prompts.PREDICT_NEXT_QUESTION_PROMPT,
       metadata={"description": "The system prompt used for generating responses."},
   )<h3>4. state.pyを更新する</h3><ul><li><p>次の属性を追加します。</p></li></ul>response: Annotated[Sequence[AnyMessage], add_messages]
next_question : Annotated[Sequence[AnyMessage], add_messages]<h3>5. 検索グラフを再実行する</h3><ul><li><p>次の検索クエリをもう一度入力してください。</p></li></ul>What was NovaTech Solutions total revenue in Q1 2025?<p>システムは入力を処理し、以下に示すように、ユーザーが尋ねる可能性のある 3 つの関連する質問を予測します。</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltd8d4de9396ca4853/6a17f87be31791dc742d59c7/70e855a2e4edc0ba5a147588df0de30eb081d053-1600x777.png" alt="LangGraphとElasticsearchを使用して3つのユーザーの質問による検索グラフを実行する" /><h2>まとめ</h2><p>LangGraph Studio と CLI 内に取得エージェント テンプレートを統合すると、いくつかの重要な利点が得られます。</p><ul><li><p><strong>開発の加速</strong>: テンプレートと視覚化ツールにより、検索ワークフローの作成とデバッグが効率化され、開発時間が短縮されます。</p></li><li><p><strong>シームレスな展開</strong>: API と自動スケーリングの組み込みサポートにより、環境間でのスムーズな展開が保証されます。</p></li><li><p><strong>簡単な更新:</strong>ワークフローの変更、新しい機能の追加、追加のノードの統合が簡単なので、検索プロセスの拡張と強化が容易になります。</p></li><li><p><strong>永続メモリ</strong>: システムはエージェントの状態と知識を保持し、一貫性と信頼性を向上させます。</p></li><li><p><strong>柔軟なワークフロー モデリング</strong>: 開発者は、特定のユース ケースに合わせて検索ロジックと通信ルールをカスタマイズできます。</p></li><li><p><strong>リアルタイムの対話とデバッグ</strong>: 実行中のエージェントと対話できるため、効率的なテストと問題解決が可能になります。</p></li></ul><p>これらの機能を活用することで、組織はデータのアクセシビリティとユーザー エクスペリエンスを向上させる強力で効率的かつスケーラブルな検索システムを構築できます。</p><p>このプロジェクトの完全なソースコードは<a href="https://github.com/elastic/elasticsearch-labs/tree/main/supporting-blog-content/langraph-retrieval-agent-template-demo">GitHub</a>で入手できます。</p>]]></content:encoded>
    <link>https://www.elastic.co/search-labs/blog/build-rag-workflow-langgraph-elasticsearch</link>
    <guid isPermaLink="true">https://www.elastic.co/search-labs/blog/build-rag-workflow-langgraph-elasticsearch</guid>
    <category><![CDATA[AI]]></category>
    <dc:creator><![CDATA[Neha Saini]]></dc:creator>
    <enclosure url="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt0c9f03d2c1a9cb4c/6a17f87d0b0bed3781dd377c/17b7e7b336f73e232375d1add582ae5f6c52a279-1440x840.png" length="0" type="image/png"/>
    <pubDate>Fri, 25 Apr 2025 00:00:00 GMT</pubDate>
  </item>
  </channel>
</rss>