검색 결과 콘텐츠 블록은 현재 베타 버전입니다. 이 기능을 활성화하려면 search-results-2025-01-01베타 헤더를 사용하세요.
검색 결과 콘텐츠 블록은 적절한 소스 귀속과 함께 자연스러운 인용을 가능하게 하여 사용자 정의 애플리케이션에 웹 검색 품질의 인용을 제공합니다. 이 기능은 Claude가 소스를 정확하게 인용해야 하는 RAG(Retrieval-Augmented Generation) 애플리케이션에 특히 강력합니다.
{"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}}
from anthropic import Anthropicfrom anthropic.types.beta import( BetaMessageParam, BetaTextBlockParam, BetaSearchResultBlockParam, BetaToolResultBlockParam)client = Anthropic()# Define a knowledge base search toolknowledge_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"]}}# Function to handle the tool calldefsearch_knowledge_base(query):# Your search logic here# Returns search results in the correct formatreturn[ BetaSearchResultBlockParam(type="search_result", source="https://docs.company.com/product-guide", title="Product Configuration Guide", content=[ BetaTextBlockParam(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}), BetaSearchResultBlockParam(type="search_result", source="https://docs.company.com/troubleshooting", title="Troubleshooting Guide", content=[ BetaTextBlockParam(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})]# Create a message with the toolresponse = client.beta.messages.create( model="claude-opus-4-20250514", max_tokens=1024, betas=["search-results-2025-01-01"], tools=[knowledge_base_tool], messages=[ BetaMessageParam( role="user", content="How do I configure the timeout settings?")])# When Claude calls the tool, provide the search resultsif response.content[0].type=="tool_use": tool_result = search_knowledge_base(response.content[0].input["query"])# Send the tool result back final_response = client.beta.messages.create( model="claude-opus-4-20250514", max_tokens=1024, betas=["search-results-2025-01-01"], messages=[ BetaMessageParam(role="user", content="How do I configure the timeout settings?"), BetaMessageParam(role="assistant", content=response.content), BetaMessageParam( role="user", content=[ BetaToolResultBlockParam(type="tool_result", tool_use_id=response.content[0].id, content=tool_result # Search results go here)])])
from anthropic import Anthropicfrom anthropic.types.beta import( BetaMessageParam, BetaTextBlockParam, BetaSearchResultBlockParam)client = Anthropic()# Provide search results directly in the user messageresponse = client.beta.messages.create( model="claude-opus-4-20250514", max_tokens=1024, betas=["search-results-2025-01-01"], messages=[ BetaMessageParam( role="user", content=[ BetaSearchResultBlockParam(type="search_result", source="https://docs.company.com/api-reference", title="API Reference - Authentication", content=[ BetaTextBlockParam(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}), BetaSearchResultBlockParam(type="search_result", source="https://docs.company.com/quickstart", title="Getting Started Guide", content=[ BetaTextBlockParam(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}), BetaTextBlockParam(type="text", text="Based on these search results, how do I authenticate API requests and what are the rate limits?")])])print(response.model_dump_json(indent=2))
검색 결과가 제공되는 방식에 관계없이 Claude는 해당 정보를 사용할 때 자동으로 인용을 포함합니다:
{"role":"assistant","content":[{"type":"text","text":"To authenticate API requests, you need to include an API key in the Authorization header","citations":[{"type":"search_result_location","source":"https://docs.company.com/api-reference","title":"API Reference - Authentication","cited_text":"All API requests must include an API key in the Authorization header","search_result_index":0,"start_block_index":0,"end_block_index":0}]},{"type":"text","text":". You can generate API keys from your dashboard","citations":[{"type":"search_result_location","source":"https://docs.company.com/api-reference","title":"API Reference - Authentication","cited_text":"Keys can be generated from the dashboard","search_result_index":0,"start_block_index":0,"end_block_index":0}]},{"type":"text","text":". The rate limits are 1,000 requests per hour for the standard tier and 10,000 requests per hour for the premium tier.","citations":[{"type":"search_result_location","source":"https://docs.company.com/api-reference","title":"API Reference - Authentication","cited_text":"Rate limits: 1000 requests per hour for standard tier, 10000 for premium","search_result_index":0,"start_block_index":0,"end_block_index":0}]}]}
{"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."}]}
Claude는 start_block_index와 end_block_index 필드를 사용하여 특정 블록을 인용할 수 있습니다.
# First message with top-level search resultsmessages =[ BetaMessageParam( role="user", content=[ BetaSearchResultBlockParam(type="search_result", source="https://docs.company.com/overview", title="Product Overview", content=[ BetaTextBlockParam(type="text", text="Our product helps teams collaborate...")], citations={"enabled":True}), BetaTextBlockParam(type="text", text="Tell me about this product and search for pricing information")])]# Claude might respond and call a tool to search for pricing# Then you provide tool results with more search results
# In tool resultstool_result =[ BetaSearchResultBlockParam(type="search_result", source="https://docs.company.com/guide", title="User Guide", content=[BetaTextBlockParam(type="text", text="Configuration details...")], citations={"enabled":True}), BetaTextBlockParam(type="text", text="Additional context: This applies to version 2.0 and later.")]# In top-level contentuser_content =[ BetaSearchResultBlockParam(type="search_result", source="https://research.com/paper", title="Research Paper", content=[BetaTextBlockParam(type="text", text="Key findings...")], citations={"enabled":True}),{"type":"image","source":{"type":"url","url":"https://example.com/chart.png"}}, BetaTextBlockParam(type="text", text="How does the chart relate to the research findings?")]
기본적으로 검색 결과에 대한 인용은 비활성화되어 있습니다. 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 애플리케이션을 위한 자연스러운 인용
독점 지식 기반과 인터페이싱할 때 소스 귀속
검색 결과를 반환하는 사용자 정의 도구에 대한 웹 검색 품질의 인용
citations 필드가 생략되면 인용은 기본적으로 비활성화됩니다.
인용은 전부 아니면 전무입니다: 요청의 모든 검색 결과에서 인용이 활성화되어야 하거나 모두 비활성화되어야 합니다. 다른 인용 설정을 가진 검색 결과를 혼합하면 오류가 발생합니다. 일부 소스에 대해 인용을 비활성화해야 하는 경우 해당 요청의 모든 검색 결과에 대해 비활성화해야 합니다.