Anthropic Claude 모델을 사용한 웹 검색

웹 검색은 Claude 모델이 웹의 실시간 데이터를 사용하여 지식을 보강할 수 있는 기능입니다. Claude 모델은 웹 검색 기능에 서드 파티 검색 제공업체를 사용합니다. 웹 검색 기능은 특히 소스를 정확하게 인용해야 하는 RAG (검색 증강 생성) 애플리케이션에 유용합니다.

웹 검색 기능은 다음과 같은 사용 사례에 적합합니다.

  • 최신 기술 문서 검색: 소프트웨어 개발자는 Claude에게 최신 API 문서 또는 기술 사양에 관해 질문할 수 있으며, Claude는 소스 문서에서 직접 정보를 검색하고 종합할 수 있습니다.
  • 비즈니스 및 시장 정보 수집: 비즈니스 애널리스트는 의사결정 프로세스를 지원하기 위해 현재 시장 데이터, 회사 정보 또는 업계 뉴스를 수집할 수 있습니다.
  • 조사 지원: 지식 근로자는 Claude를 여러 웹 소스의 정보를 찾고, 종합하고, 설명하면서 정확한 인용을 유지할 수 있는 조사 어시스턴트로 사용할 수 있습니다.
  • 고객 지원: 고객 서비스 애플리케이션은 회사 웹사이트에서 최신 제품 정보, 가격 또는 지원 문서에 액세스할 수 있습니다.

지원되는 모델

Vertex AI는 다음 Anthropic Claude 모델의 웹 검색을 지원합니다.

API 요청에 새 Anthropic 도구 정의 (web_search)를 제공하고 베타 헤더를 사용하여 요청을 전송하여 웹 검색을 사용 설정합니다. "anthropic-beta": "web-search-2025-03-05"

예를 들어 다음 코드 스니펫은 웹 검색을 사용하여 실시간 날씨 정보를 가져옵니다.

response = await client.messages.create(
    model="claude-4-sonnet-latest",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": "What is the weather in San Francisco?"
    }],
    tools=[{
        "type": "web_search_20250305",
        "name": "web_search",
        "max_uses": 5
    }]
)

선택사항 필드를 사용하여 허용된 도메인과 차단된 도메인을 지정할 수도 있습니다. 예를 들면 다음과 같습니다.

tools=[{
  ...
  # Only one of allowed_domains and blocked_domains can be provided.
  # allowed_domains excludes everything except the specified domains
    "allowed_domains": ["example.com", "example.org"],

  # blocked_domains includes everything except the specified domains
  # Use the `NOT site:` search operator
    "blocked_domains": ["example.net"],
}]

선택사항 필드에 대한 자세한 내용은 Claude 웹 검색 도구 문서를 참고하세요.

모델이 웹 검색이 필요하다고 판단하면 더 이상 도구 호출이 필요하지 않을 때까지 API가 웹 검색 도구를 호출합니다. 대답에는 중간 검색에 관한 세부정보가 포함되며 결과는 암호화됩니다.

다음 코드 스니펫은 웹 검색이 포함된 대답의 예입니다.

{
  ...
  "role": "assistant",
  "content": [
    // Initial output from the model
    {
      "type": "text",
      "text": "I need to search the web to answer this question about the weather in San Francisco."
    },
    {
      "type": "server_tool_use",
      "id": "srvtoolu_9a90a390a",
      "name": "web_search",
      "input": {
        "query": "What is the weather in San Francisco?",
      }
    },
    // API sees an `</antml:function_calls>` stop sequence here, sees that
    // the tool use is for a server-side tool, and then runs that
    // tool. If there is a mix of client and server-side, the API would
    // need to return to the client and let it pass back client tool results
    // before continuing with server tools.
    {
      "type": "web_search_tool_result",
      // "name": "web_search", use this to determine what types of blocks are inside `content`
      "tool_use_id": "srvtoolu_9a90a390a",
      "content": [
        {
          "type": "web_search_result",
          "uri": "https://weather.com",
          "title": "National and Local Weather",
          "encrypted_content": "eyJlbmNyeXB0ZWRfa2V5Ijoic2VjcmV0LW...", // encrypted list of snippets from the web search provider
        },
        {
          "type": "web_search_result",
          "uri": "https://accuweather.com",
          "title": "San Francisco, CA Hourly Weather",
          "encrypted_content": "yaJlbmNyeXB0ZWRfa2V5Ijoic2VjcmV0LW...", // encrypted list of snippets from the web search provider
        },
      ],
    },
    // Server starts a new sampling run with the above content appended (unencrypted)
    // to the original request. Everything below is completion content from the
    // second sampling run.
    {
      "type": "text",
      "text": "The current weather in San Francisco, CA is 65 degrees Fahrenheit and partly cloudy."
    }
  ],
  // Server output is no longer 1-to-1 with a single sampling run. From the
  // user's perspective, there is just one "Message" with a single id
  "id": "msg_a930390d3",
  "usage": {
    "input_tokens": 3029,
    "output_tokens": 6039,
    "server_tool_use": {
      "web_search_requests": 2
    }
  },
  "stop_reason": "end_turn"
}

웹 검색을 통한 스트리밍

스트리밍이 사용 설정된 경우 모델은 스트림의 일부로 검색 이벤트를 반환합니다. 예를 들면 다음과 같습니다.

// Claude's decision to search

event: content_block_start
data: {"type": "content_block_start", "index": 1, "content_block": {"type": "server_tool_use", "id": "srvtoolu_xyz789", "name": "web_search"}}

// Search query streamed
event: content_block_delta
data: {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": "{\"query\":\"latest quantum computing breakthroughs 2025\"}"}}

// Pause while search executes

// Search results streamed
event: content_block_start
data: {"type": "content_block_start", "index": 2, "content_block": {"type": "web_search_tool_result", "tool_use_id": "srvtoolu_xyz789", "content": [{"type": "web_search_result", "title": "Quantum Computing Breakthroughs in 2025", "url": "https://example.com"}]}}

사용량은 측정되며 web_search 항목의 누적 개수가 포함된 message_delta 메시지에 포함됩니다. 예를 들면 다음과 같습니다.

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10682,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":510,"server_tool_use":{"web_search_requests":1}}}

Claude 4.0 이상 모델의 웹 검색 기능은 Anthropic Claude 모델의 선택적 기능입니다. 요청에 웹 검색 도구를 제공하여 사용 설정할 수 있습니다. 이 기능을 활성화하면 Vertex AI에 Claude 모델이 요청에서 파생된 검색어를 Anthropic에서 선택한 서드 파티 검색 서비스 제공업체에 전송하도록 지시하는 것입니다. Google은 이 서드 파티 제공업체의 데이터 처리 관행에 대해 책임을 지지 않습니다. 검색어가 전송되면 해당 데이터의 처리는 Google이 아닌 서드 파티의 자체 서비스 약관 및 개인정보처리방침에 따라 관리됩니다.

웹 검색 기능을 활성화하면 데이터 거버넌스 및 보안 상태에 직접적인 영향을 미칩니다. 고객 관리 암호화 키 (CMEK) 및 데이터 상주와 같은 Vertex AI 추가 약정은 서드 파티 검색 제공업체에서 처리하는 동안에는 데이터에 적용되지 않습니다. 소비자 프로젝트가 VPC-SC 경계에 있는 경우 Vertex AI는 다음 오류 메시지와 함께 요청을 거부합니다.

{
  "error": {
    "code": 400,
    "message": "The requested model does not serve requests restricted by VPCSC",
    "status": "FAILED_PRECONDITION"
  }
}

이 기능은 Claude 4.0 및 이후 모델에서만 사용할 수 있으며 Vertex AI의 이전 Claude 모델에서는 사용할 수 없습니다. Anthropic 웹 검색 기능이 웹 검색 기능을 사용하는 경우 호출할 수 있는 서드 파티 검색 서비스 목록:

가격 책정

웹 검색은 웹 요청량을 기준으로 표준 Messages API 사용량의 부가기능으로 가격이 책정됩니다. 추가 샘플링 호출로 인해 사용자에게 추가 입력 토큰에 대한 요금도 청구됩니다.

자세한 내용은 가격 책정을 참조하세요.