Web Search Plugin 是一个为 AI 模型提供实时网络搜索能力的插件,支持多种搜索引擎(Google、Bing、BingCN、Arxiv、SearchXNG),能够自动重写搜索查询并格式化搜索结果。
{
"model": "claude-3-7-sonnet-20250219",
"retry_times": 5,
"owner": "anthropic",
"type": 1,
"plugin": {
"web-search": {
"enable": true,
"force_search": true,
"search_rewrite": {
"enable": true,
"add_rewrite_usage": true,
"rewrite_usage_field": "rewrite_usage"
},
"need_reference": true,
"reference_location": "content",
"search_from": [
{
"type": "google",
"spec": {
"api_key": "api key",
"cx": "cx"
}
}
]
}
}
}
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
model |
string | 是 | - | 使用的 AI 模型名称 |
retry_times |
int | 否 | 3 | 请求失败时的重试次数 |
type |
int | 是 | - | 模型类型标识 |
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
enable |
bool | 是 | false | 是否启用 Web Search 插件 |
force_search |
bool | 否 | false | 是否默认为所有请求启用网络搜索,默认情况下,如果用户请求中没有 web_search_options 字段,则不启用网络搜索 |
max_results |
int | 否 | 10 | 每次搜索返回的最大结果数量 |
need_reference |
bool | 否 | false | 是否在回答中包含引用信息 |
reference_location |
string | 否 | "content" | 引用位置,可选值:content、references ... 等 |
reference_format |
string | 否 | "References:\n%s" | 引用格式模板,必须包含 %s 占位符 |
default_language |
string | 否 | - | 默认搜索语言 |
prompt_template |
string | 否 | - | 自定义提示词模板 |
search_rewrite)| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
enable |
bool | 否 | false | 是否启用搜索查询重写功能 |
model_name |
string | 否 | - | 用于重写查询的模型名称,为空时使用当前请求的模型 |
timeout_millisecond |
uint32 | 否 | 10000 | 重写请求超时时间(毫秒) |
max_count |
int | 否 | 3 | 最大重写查询数量 |
add_rewrite_usage |
bool | 否 | false | 是否在响应中添加重写使用统计信息 |
rewrite_usage_field |
string | 否 | "rewrite_usage" | 重写使用统计信息字段名称 |
search_from)每个搜索引擎配置包含以下字段:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
type |
string | 是 | 搜索引擎类型:google、bing、bingcn、arxiv、searchxng |
max_results |
int | 否 | 该引擎的最大结果数量 |
spec |
object | 视类型而定 | 引擎特定的配置参数 |
spec){
"type": "google",
"spec": {
"api_key": "your_google_api_key",
"cx": "your_custom_search_engine_id"
}
}
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
api_key |
string | 是 | Google Custom Search API 密钥 |
cx |
string | 是 | Google 自定义搜索引擎 ID |
spec){
"type": "bing",
"spec": {
"api_key": "your_bing_api_key"
}
}
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
api_key |
string | 是 | Bing Search API 密钥 |
spec){
"type": "bingcn",
"spec": {}
}
BingCN 搜索引擎无需额外配置参数,使用默认配置。
spec){
"type": "arxiv",
"spec": {}
}
Arxiv 搜索引擎无需额外配置参数。
spec){
"type": "searchxng",
"spec": {
"base_url": "https://searchxng.com"
}
}
用户可以在请求中添加 web_search_options 字段来控制搜索行为:
{
"model": "claude-3-7-sonnet-20250219",
"messages": [
{
"role": "user",
"content": "请搜索最新的AI技术发展"
}
],
"web_search_options": {
"enable": true,
"search_context_size": "medium"
}
}
| 字段 | 类型 | 可选值 | 说明 |
|---|---|---|---|
enable |
bool | - | 是否启用搜索,如果为 false,则不启用搜索 |
search_context_size |
string | low、medium、high |
控制搜索上下文的大小,影响搜索查询的数量和深度 |
search_context_size 字段用于控制搜索的广度和深度:
low:生成 1 个搜索查询,适合简单、直接的问题medium:生成 3 个搜索查询(默认值),适合大多数场景high:生成 5 个搜索查询,适合复杂问题或需要全面信息的场景该字段会覆盖配置中 search_rewrite.max_count 的值,允许用户根据具体需求动态调整搜索策略。
Web Search 插件在以下情况下会被启用:
force_search 为 true 时,所有请求都会启用搜索force_search 为 false 时,只有包含 web_search_options 字段的请求才会启用搜索{
"model": "claude-3-7-sonnet-20250219",
"messages": [
{
"role": "user",
"content": "今天的天气如何?"
}
],
"web_search_options": {
"enable": true
}
}
{
"model": "claude-3-7-sonnet-20250219",
"messages": [
{
"role": "user",
"content": "分析当前人工智能在医疗领域的最新应用和发展趋势"
}
],
"web_search_options": {
"enable": true,
"search_context_size": "high"
}
}
enable 设置为 truesearch_from 数组中添加至少一个搜索引擎配置force_search 控制是否默认启用搜索web_search_options 字段控制搜索行为启用 search_rewrite.enable 后,插件会使用 AI 模型自动优化用户的搜索查询,提高搜索结果的相关性。
当 need_reference 为 true 时:
[1]、[2] 等reference_location 控制引用显示位置reference_format 自定义引用格式用户可以通过 search_context_size 参数动态调整搜索的深度:
low 减少延迟high 获取更全面的信息medium 平衡性能和质量search_context_size 设置越高,延迟越大web_search_options 字段会在处理后自动从请求中移除enable 是否为 trueweb_search_options 字段(当 force_search 为 false 时)