Claude Platform Docs
  • メッセージ
  • マネージドエージェント
  • 管理

Search...
⌘K
はじめに
Claudeの紹介クイックスタート
Claudeで構築する
機能の概要Messages APIの使用停止理由とフォールバック拒否とフォールバックフォールバッククレジット
モデルの機能
拡張思考適応型思考エフォートタスク予算(ベータ版)高速モード(リサーチプレビュー)構造化出力引用メッセージのストリーミングバッチ処理検索結果拒否のストリーミング多言語サポート埋め込み
ツール
概要ツール使用の仕組みチュートリアル:ツールを使うエージェントの構築ツールの定義ツール呼び出しの処理並列ツール使用Tool Runner(SDK)厳密なツール使用プロンプトキャッシングを使ったツール使用サーバーツールトラブルシューティングWeb検索ツールWeb取得ツールコード実行ツールアドバイザーツールメモリツールBashツールコンピュータ使用ツールテキストエディタツール
ツールインフラストラクチャ
ツールリファレンスツールコンテキストの管理ツールの組み合わせツール検索プログラムによるツール呼び出しきめ細かいツールストリーミング
コンテキスト管理
コンテキストウィンドウコンパクションコンテキスト編集プロンプトキャッシング会話途中のシステムメッセージオーケストレーションモードの構築キャッシュ診断(ベータ版)トークンカウント
ファイルの操作
Files APIPDFサポート画像とビジョン
スキル
概要クイックスタートベストプラクティスエンタープライズ向けスキルAPIでのスキル
MCP
リモートMCPサーバーMCPコネクタ
クラウドプラットフォーム上のClaude
Amazon BedrockAmazon Bedrock(レガシー)AWS上のClaude PlatformMicrosoft FoundryVertex AI

Log in
検索結果
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Claude Platform Docs

Solutions

  • AI agents
  • Code modernization
  • Coding
  • Customer support
  • Education
  • Financial services
  • Government
  • Life sciences

Partners

  • Claude on AWS
  • Claude on Google Cloud

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Company

  • Anthropic
  • Careers
  • Economic Futures
  • Research
  • News
  • Responsible Scaling Policy
  • Security and compliance
  • Transparency

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Help and security

  • Availability
  • Status
  • Support
  • Discord

Terms and policies

  • Privacy policy
  • Responsible disclosure policy
  • Terms of service: Commercial
  • Terms of service: Consumer
  • Usage policy
メッセージ/モデルの機能

検索結果

ソース帰属付きの検索結果を提供することで、RAGアプリケーションに自然な引用を実現します


この機能はZero Data Retention(ZDR)の対象です。組織がZDR契約を締結している場合、この機能を通じて送信されたデータは、APIレスポンスが返された後に保存されることはありません。

検索結果コンテンツブロックは、適切なソース帰属を伴う自然な引用を可能にし、ウェブ検索品質の引用をカスタムアプリケーションにもたらします。この機能は、Claudeにソースを正確に引用させる必要がある「RAG」(検索拡張生成)アプリケーションにおいて特に強力です。

検索結果機能は、以下のモデルで利用可能です。

  • Claude Opus 4.8(claude-opus-4-8)
  • Claude Opus 4.7(claude-opus-4-7)
  • Claude Opus 4.6(claude-opus-4-6)
  • Claude Sonnet 4.6(claude-sonnet-4-6)
  • Claude Sonnet 4.5(claude-sonnet-4-5-20250929)
  • Claude Opus 4.5(claude-opus-4-5-20251101)
  • Claude Opus 4.1(非推奨)(claude-opus-4-1-20250805)
  • Claude Opus 4(Vertex AIを除き廃止)(claude-opus-4-20250514)
  • Claude Sonnet 4(BedrockおよびVertex AIを除き廃止)(claude-sonnet-4-20250514)
  • Claude Haiku 4.5(claude-haiku-4-5-20251001)
  • Claude Haiku 3.5(BedrockおよびVertex AIを除き廃止)(claude-3-5-haiku-20241022)

主なメリット

  • 自然な引用: あらゆるコンテンツに対してウェブ検索と同等の引用品質を実現
  • 柔軟な統合: 動的なRAGのためのツール戻り値として、または事前取得データのトップレベルコンテンツとして使用可能
  • 適切なソース帰属: 各結果には明確な帰属のためのソースとタイトル情報が含まれる
  • ドキュメントベースの回避策が不要: ドキュメントベースの回避策が不要になる
  • 一貫した引用形式: Claudeのウェブ検索機能の引用品質と形式に一致

仕組み

検索結果は、次の2つの方法で提供できます。

  1. ツール呼び出しから: カスタムツールが検索結果を返し、動的なRAGアプリケーションを実現
  2. トップレベルコンテンツとして: 事前取得またはキャッシュされたコンテンツのために、ユーザーメッセージで検索結果を直接提供

どちらの場合でも、Claudeは適切なソース帰属とともに検索結果からの情報を自動的に引用できます。

検索結果スキーマ

検索結果は以下の構造を使用します。

{
  "type": "search_result",
  "source": "https://example.com/article", // Required: Source URL or identifier
  "title": "Article Title", // Required: Title of the result
  "content": [
    // Required: Array of text blocks
    {
      "type": "text",
      "text": "The actual content of the search result..."
    }
  ],
  "citations": {
    // Optional: Citation configuration
    "enabled": true // Enable/disable citations for this result
  }
}

必須フィールド

フィールド型説明
typestring"search_result" である必要があります
sourcestringコンテンツのソースURLまたは識別子
titlestring検索結果の説明的なタイトル
contentarray実際のコンテンツを含むテキストブロックの配列

オプションフィールド

フィールド型説明
citationsobjectenabled ブール値フィールドを持つ引用設定
cache_controlobjectキャッシュ制御設定(例:{"type": "ephemeral"})

content 配列の各項目は、以下を持つテキストブロックである必要があります。

  • type:"text" である必要があります
  • text:実際のテキストコンテンツ(空でない文字列)

方法1:ツール呼び出しからの検索結果

最も強力なユースケースは、カスタムツールから検索結果を返すことです。これにより、ツールが関連コンテンツを取得して自動引用付きで返す、動的なRAGアプリケーションが可能になります。

例:ナレッジベースツール

方法2:トップレベルコンテンツとしての検索結果

ユーザーメッセージで検索結果を直接提供することもできます。これは以下の場合に便利です。

  • 検索インフラストラクチャから事前取得したコンテンツ
  • 以前のクエリからキャッシュされた検索結果
  • 外部検索サービスからのコンテンツ
  • テストおよび開発

例:直接的な検索結果

引用を含むClaudeの応答

検索結果がどのように提供されたかに関わらず、Claudeはそれらの情報を使用する際に自動的に引用を含めます。

{
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "All API requests must include an API key in the Authorization header. Keys can be generated from the dashboard.",
      "citations": [
        {
          "type": "search_result_location",
          "cited_text": "All API requests must include an API key in the Authorization header. Keys can be generated from the dashboard. Rate limits: 1000 requests per hour for standard tier, 10000 for premium.",
          "source": "https://docs.company.com/api-reference",
          "title": "API Reference - Authentication",
          "search_result_index": 0,
          "start_block_index": 0,
          "end_block_index": 1
        }
      ]
    },
    {
      "type": "text",
      "text": "\n\nTo set this up from scratch, you'll need to "
    },
    {
      "type": "text",
      "text": "sign up for an account, generate an API key from the dashboard, install the SDK using `pip install company-sdk`, and initialize the client with your API key.",
      "citations": [
        {
          "type": "search_result_location",
          "cited_text": "To get started: 1) Sign up for an account, 2) Generate an API key from the dashboard, 3) Install our SDK using pip install company-sdk, 4) Initialize the client with your API key.",
          "source": "https://docs.company.com/quickstart",
          "title": "Getting Started Guide",
          "search_result_index": 1,
          "start_block_index": 0,
          "end_block_index": 1
        }
      ]
    }
  ]
}

引用フィールド

各引用には以下が含まれます。

フィールド型説明
typestring検索結果の引用の場合、常に "search_result_location"
sourcestring元の検索結果からのソース
titlestring または null元の検索結果からのタイトル
cited_textstring引用されたブロックの全文を連結したもの。content[start_block_index:end_block_index] の内容を結合したものと等しくなります。出力トークンにはカウントされません。
search_result_indexintegerリクエスト内のすべての search_result ブロックの中で、引用された検索結果の0始まりのインデックス(すべてのメッセージおよびツール結果にわたって出現順)。

ブロックインデックスは検索結果の content 配列のスライスを識別し、cited_text はそのスライスの全文です。テキストブロックは引用可能な最小単位です。Claudeはブロック全体を引用し、ブロック内の部分文字列は引用しません。より細かい粒度の引用を得るには、検索結果のコンテンツをより小さなブロックに分割してください(複数のコンテンツブロックを参照)。

複数のコンテンツブロック

検索結果は、content 配列に複数のテキストブロックを含めることができます。

{
  "type": "search_result",
  "source": "https://docs.company.com/api-guide",
  "title": "API Documentation",
  "content": [
    {
      "type": "text",
      "text": "Authentication: All API requests require an API key."
    },
    {
      "type": "text",
      "text": "Rate Limits: The API allows 1000 requests per hour per key."
    },
    {
      "type": "text",
      "text": "Error Handling: The API returns standard HTTP status codes."
    }
  ]
}

レート制限のブロックを参照する引用は次のようになります。

{
  "type": "search_result_location",
  "cited_text": "Rate Limits: The API allows 1000 requests per hour per key.",
  "source": "https://docs.company.com/api-guide",
  "title": "API Documentation",
  "search_result_index": 0,
  "start_block_index": 1,
  "end_block_index": 2
}

この検索結果が引用されると、start_block_index と end_block_index が引用がカバーするブロックを識別し、cited_text にはそれらのブロックのテキストがそのまま含まれます。コンテンツをより小さく焦点を絞ったブロックに分割すると、Claudeにより細かい引用境界が与えられます。コンテンツを1つのブロックにまとめると、すべての引用が全文を返すことになります。これは、Citations機能のカスタムコンテンツドキュメントで使用されているものと同じモデルです。

高度な使用方法

両方の方法の組み合わせ

同じ会話内でツールベースとトップレベルの両方の検索結果を使用できます。

from anthropic.types import MessageParam, SearchResultBlockParam, TextBlockParam

# トップレベルの検索結果を含む最初のメッセージ
messages = [
    MessageParam(
        role="user",
        content=[
            SearchResultBlockParam(
                type="search_result",
                source="https://docs.company.com/overview",
                title="Product Overview",
                content=[
                    TextBlockParam(
                        type="text", text="Our product helps teams collaborate..."
                    )
                ],
                citations={"enabled": True},
            ),
            TextBlockParam(
                type="text",
                text="Tell me about this product and search for pricing information",
            ),
        ],
    )
]

# Claudeは応答し、価格を検索するためにツールを呼び出す場合があります
# 次に、追加の検索結果を含むツール結果を提供します

他のコンテンツタイプとの組み合わせ

どちらの方法も、検索結果と他のコンテンツの混在をサポートしています。

from anthropic.types import SearchResultBlockParam, TextBlockParam

# ツール結果内
tool_result = [
    SearchResultBlockParam(
        type="search_result",
        source="https://docs.company.com/guide",
        title="User Guide",
        content=[TextBlockParam(type="text", text="Configuration details...")],
        citations={"enabled": True},
    ),
    TextBlockParam(
        type="text", text="Additional context: This applies to version 2.0 and later."
    ),
]

# トップレベルコンテンツ内
user_content = [
    SearchResultBlockParam(
        type="search_result",
        source="https://research.com/paper",
        title="Research Paper",
        content=[TextBlockParam(type="text", text="Key findings...")],
        citations={"enabled": True},
    ),
    {
        "type": "image",
        "source": {"type": "url", "url": "https://example.com/chart.png"},
    },
    TextBlockParam(
        type="text", text="How does the chart relate to the research findings?"
    ),
]

キャッシュ制御

パフォーマンス向上のためにキャッシュ制御を追加します。

{
  "type": "search_result",
  "source": "https://docs.company.com/guide",
  "title": "User Guide",
  "content": [{ "type": "text", "text": "..." }],
  "cache_control": {
    "type": "ephemeral"
  }
}

引用制御

デフォルトでは、検索結果の引用は無効になっています。citations 設定を明示的に設定することで引用を有効にできます。

{
  "type": "search_result",
  "source": "https://docs.company.com/guide",
  "title": "User Guide",
  "content": [{ "type": "text", "text": "Important documentation..." }],
  "citations": {
    "enabled": true // Enable citations for this result
  }
}

citations.enabled が true に設定されている場合、Claudeは検索結果からの情報を使用する際に引用参照を含めます。これにより以下が可能になります。

  • カスタムRAGアプリケーションのための自然な引用
  • 独自のナレッジベースとのインターフェース時のソース帰属
  • 検索結果を返すあらゆるカスタムツールに対するウェブ検索品質の引用


引用はオール・オア・ナッシングです。リクエスト内のすべての検索結果で引用を有効にするか、すべてで無効にする必要があります。異なる引用設定を持つ検索結果を混在させるとエラーになります。

ベストプラクティス

ツールベースの検索(方法1)の場合

  • 動的コンテンツ: リアルタイム検索および動的なRAGアプリケーションに使用
  • エラー処理: 検索が失敗した場合は適切なメッセージを返す
  • 結果の制限: コンテキストのオーバーフローを避けるため、最も関連性の高い結果のみを返す

トップレベル検索(方法2)の場合

  • 事前取得コンテンツ: すでに検索結果がある場合に使用
  • バッチ処理: 複数の検索結果を一度に処理するのに最適
  • テスト: 既知のコンテンツで引用動作をテストするのに最適

一般的なベストプラクティス

  1. 結果を効果的に構造化する:

    • 明確で永続的なソースURLを使用する
    • 説明的なタイトルを提供する
    • 長いコンテンツを論理的なテキストブロックに分割し、Claudeにより細かい引用境界を与える
  2. 一貫性を維持する:

    • アプリケーション全体で一貫したソース形式を使用する
    • タイトルがコンテンツを正確に反映していることを確認する
    • フォーマットの一貫性を保つ
  3. エラーを適切に処理する:

    def search_with_fallback(query):
        try:
            results = perform_search(query)
            if not results:
                return {"type": "text", "text": "No results found."}
            return format_as_search_results(results)
        except Exception as e:
            return {"type": "text", "text": f"Search error: {str(e)}"}

制限事項

  • 検索結果コンテンツブロックは、Claude API、Amazon Bedrock、およびGoogle CloudのVertex AIで利用可能です
  • 検索結果内ではテキストコンテンツのみがサポートされています(画像やその他のメディアは不可)
  • content 配列には少なくとも1つのテキストブロックが含まれている必要があります

次のステップ


引用

ドキュメント、カスタムコンテンツ、検索結果全体で引用がどのように機能するかを学びます。

ウェブ検索ツール

サーバーツールを使用して、Claudeにウェブを検索させ、ソースを自動的に引用させます。


Messages APIリファレンス

コンテンツブロックタイプを含む、完全なMessages APIドキュメントを参照します。

Was this page helpful?

  • 主なメリット
  • 仕組み
  • 検索結果スキーマ
  • 必須フィールド
  • オプションフィールド
  • 方法1:ツール呼び出しからの検索結果
  • 例:ナレッジベースツール
  • 方法2:トップレベルコンテンツとしての検索結果
  • 例:直接的な検索結果
  • 引用を含むClaudeの応答
  • 引用フィールド
  • 複数のコンテンツブロック
  • 高度な使用方法
  • 両方の方法の組み合わせ
  • 他のコンテンツタイプとの組み合わせ
  • キャッシュ制御
  • 引用制御
  • ベストプラクティス
  • ツールベースの検索(方法1)の場合
  • トップレベル検索(方法2)の場合
  • 一般的なベストプラクティス
  • 制限事項
  • 次のステップ
from anthropic.types import (
    MessageParam,
    TextBlockParam,
    SearchResultBlockParam,
    ToolResultBlockParam,
)

client = Anthropic()

# ナレッジベース検索ツールを定義
knowledge_base_tool = {
    "name": "search_knowledge_base",
    "description": "Search the company knowledge base for information",
    "input_schema": {
        "type": "object",
        "properties": {"query": {"type": "string", "description": "The search query"}},
        "required": ["query"],
    },
}


# ツール呼び出しを処理する関数
def search_knowledge_base(query):
    # ここに検索ロジックを記述
    # 正しい形式で検索結果を返す
    return [
        SearchResultBlockParam(
            type="search_result",
            source="https://docs.company.com/product-guide",
            title="Product Configuration Guide",
            content=[
                TextBlockParam(
                    type="text",
                    text="To configure the product, navigate to Settings > Configuration. The default timeout is 30 seconds, but can be adjusted between 10-120 seconds based on your needs.",
                )
            ],
            citations={"enabled": True},
        ),
        SearchResultBlockParam(
            type="search_result",
            source="https://docs.company.com/troubleshooting",
            title="Troubleshooting Guide",
            content=[
                TextBlockParam(
                    type="text",
                    text="If you encounter timeout errors, first check the configuration settings. Common causes include network latency and incorrect timeout values.",
                )
            ],
            citations={"enabled": True},
        ),
    ]


# ツールを指定してメッセージを作成
response = client.messages.create(
    model="claude-opus-4-8",  # Works with all supported models
    max_tokens=1024,
    tools=[knowledge_base_tool],
    messages=[
        MessageParam(role="user", content="How do I configure the timeout settings?")
    ],
)

# Claudeがツールを呼び出したら、検索結果を提供
if response.content[0].type == "tool_use":
    tool_result = search_knowledge_base(response.content[0].input["query"])

    # ツール結果を返送
    final_response = client.messages.create(
        model="claude-opus-4-8",  # Works with all supported models
        max_tokens=1024,
        messages=[
            MessageParam(
                role="user", content="How do I configure the timeout settings?"
            ),
            MessageParam(role="assistant", content=response.content),
            MessageParam(
                role="user",
                content=[
                    ToolResultBlockParam(
                        type="tool_result",
                        tool_use_id=response.content[0].id,
                        content=tool_result,  # Search results go here
                    )
                ],
            ),
        ],
    )
from anthropic.types import MessageParam, TextBlockParam, SearchResultBlockParam

client = Anthropic()

# 検索結果をユーザーメッセージ内で直接提供します
response = client.messages.create(
    model="claude-opus-4-8",
    max_tokens=1024,
    messages=[
        MessageParam(
            role="user",
            content=[
                SearchResultBlockParam(
                    type="search_result",
                    source="https://docs.company.com/api-reference",
                    title="API Reference - Authentication",
                    content=[
                        TextBlockParam(
                            type="text",
                            text="All API requests must include an API key in the Authorization header. Keys can be generated from the dashboard. Rate limits: 1000 requests per hour for standard tier, 10000 for premium.",
                        )
                    ],
                    citations={"enabled": True},
                ),
                SearchResultBlockParam(
                    type="search_result",
                    source="https://docs.company.com/quickstart",
                    title="Getting Started Guide",
                    content=[
                        TextBlockParam(
                            type="text",
                            text="To get started: 1) Sign up for an account, 2) Generate an API key from the dashboard, 3) Install our SDK using pip install company-sdk, 4) Initialize the client with your API key.",
                        )
                    ],
                    citations={"enabled": True},
                ),
                TextBlockParam(
                    type="text",
                    text="Based on these search results, how do I authenticate API requests and what are the rate limits?",
                ),
            ],
        )
    ],
)

print(response)
start_block_indexinteger検索結果の content 配列内で最初に引用されたブロックの0始まりのインデックス。
end_block_indexinteger検索結果の content 配列内で引用されたブロック範囲の排他的終了インデックス。常に start_block_index より大きくなります。
プロンプトキャッシング

cache_control で検索結果をキャッシュし、繰り返しリクエストのコストとレイテンシを削減します。