概述
在调用百度AI搜索API进行联网搜索总结时,可设置一系列特定的用户输入,通过完全匹配或者语义匹配的方式命中后,进行特定知识库检索后总结、特定知识库检索和联网搜索后总结、预置特定回答等方式进行输出,确保符合品牌立场、人设、形象,该接口仅支持智能搜索生成服务。
在调用该接口前:
新增问答策略
接口定义
URL |
qianfan.baidubce.com/v2/ai_search/qa_strategy |
Method |
POST |
Content-Type |
application/json |
请求结构
POST /v2/ai_search/qa_strategy HTTP/1.1
HOST: qianfan.baidubce.com
Authorization: Bearer <AppBuilder API Key>
Content-Type: application/json
{
"query": "xx是组装厂吗?",
"config_id": "0035f63a-74fb-4615-b1ea-96f9e1f9ed55",
"query_match_strategy": {
"name": "keyword",
"keywords":["xx","组装厂"]
},
"answer_strategy": {
"name": "preset_answer",
"preset_answer_strategy_detail": {
"content": "xx不是组装厂",
"references": [ { } ]
}
}
}
参数名称 |
描述 |
Authorization |
AppBuilder API Key请前往控制台获取。 |
请求参数
参数名称 |
类型 |
是否必填 |
描述 |
query |
string |
是 |
问答query,不超过256个字符。 |
config_id |
string |
否 |
策略配置ID,需要提前调用配置接口创建ID。 |
query_match_strategy |
object |
是 |
query匹配策略。 |
answer_strategy |
object |
是 |
回复策略。 |
query_match_strategy对象
参数名称 |
类型 |
是否必填 |
描述 |
name |
string |
是 |
匹配策略名称。可取值: exact:完全匹配 semantic:语义匹配 keyword:关键词匹配 |
similarity_threshold |
float |
否 |
当语义匹配时,该参数生效,值介于 0~1 之间,默认 0.9。 |
keywords |
array<string> |
否 |
当关键词匹配时,该参数生效,范围为0~256。 |
answer_strategy对象
参数名称 |
类型 |
是否必填 |
描述 |
name |
string |
是 |
回复策略 |
preset_answer_strategy_detail |
object |
否 |
预置回答策略 |
knowledge_base_answer_strategy_detail |
object |
否 |
知识库回答策略 |
answer_strategy.preset_answer_strategy_detail对象
参数名称 |
类型 |
是否必填 |
描述 |
content |
string |
是 |
预设答案内容 |
references |
array<reference> |
是 |
参考信息来源的相关参数配置。 |
answer_strategy.preset_answer_strategy_detail.Reference
参数名称 |
类型 |
是否必填 |
描述 |
icon |
string |
否 |
站点图标 |
id |
int |
是 |
引用编号1、2、3 |
title |
string |
是 |
网页标题 |
url |
string |
是 |
网页地址 |
web_anchor |
string |
是 |
网站锚文本或网站标题 |
content |
string |
是 |
网站内容 |
date |
string |
否 |
网页日期 |
type |
string |
否 |
检索资源类型: web:网页 image:图像内容 video:视频内容 |
image |
ImageDetail |
否 |
图片详情 |
video |
VideoDetail |
否 |
视频详情 |
answer_strategy.preset_answer_strategy_detail.reference.ImageDetail
参数名称 |
类型 |
是否必填 |
描述 |
url |
string |
否 |
图片链接 |
height |
string |
否 |
图片高度 |
width |
string |
否 |
图片宽度 |
answer_strategy.preset_answer_strategy_detail.reference.VideoDetail
参数名称 |
类型 |
是否必填 |
描述 |
url |
string |
否 |
视频链接 |
height |
string |
否 |
视频高度 |
width |
string |
否 |
视频宽度 |
size |
string |
否 |
视频大小,单位Bytes。 |
duration |
string |
否 |
视频长度,单位秒。 |
hover_pic |
string |
否 |
视频封面图 |
answer_strategy.knowledge_base_answer_strategy_detail对象
参数名称 |
类型 |
是否必填 |
描述 |
knowledge_base_ids |
array<string> |
是 |
知识库ID数组。 |
document_ids |
array<string> |
是 |
文档ID数组。 |
top_k |
int |
否 |
最相关的前k个结果,默认top6。 |
调用示例
curl --location 'https://qianfan.baidubce.com/v2/ai_search/qa_strategy' \
--header 'Content-Type: application/json' \
--header 'Authorization: <token>' \
--data '{ "query": "xx是组装厂吗?", "query_match_strategy": {"name": "keyword","keywords":[ "xx","组装厂"]}, "answer_strategy": {"name": "preset_answer",
"preset_answer_strategy_detail": {"content": "xx不是组装厂","references": [{}] } }}'
响应参数
参数名称 |
类型 |
描述 |
request_id |
string |
请求ID。 |
code |
string |
错误码,当发生异常时返回。 |
message |
string |
错误消息,当发生异常时返回。 |
响应示例
删除问答策略
接口定义
URL |
qianfan.baidubce.com/v2/ai_search/qa_strategy |
Method |
DELETE |
Content-Type |
application/json |
请求结构
DELETE /v2/ai_search/qa_strategy HTTP/1.1
HOST: qianfan.baidubce.com
Authorization: Bearer <AppBuilder API Key>
Content-Type: application/json
?query=%E5%B0%8F%E7%B1%B3%E6%98%AF%E7%BB%84%E8%A3%85%E5%8E%82%E5%90%97%EF%BC%9F?
参数名称 |
描述 |
Authorization |
AppBuilder API Key请前往控制台获取。 |
Query参数
参数名称 |
类型 |
是否必须 |
描述 |
query |
string |
是 |
需要对query进行urlencode。 |
config_id |
string |
否 |
策略配置ID。 |
调用示例
curl -X "DELETE" \
-H "Authorization: <token> " \
--location 'https://qianfan.baidubce.com/v2/ai_search/qa_strategy?query=%E5%B0%8F%E7%B1%B3%E6%98%AF%E7%BB%84%E8%A3%85%E5%8E%82%E5%90%97%EF%BC%9F'
响应参数
参数名称 |
类型 |
描述 |
request_id |
string |
请求ID。 |
code |
string |
错误码,当发生异常时返回。 |
message |
string |
错误消息,当发生异常时返回。 |
响应示例
分页查询问答策略
接口定义
URL |
qianfan.baidubce.com/v2/ai_search/qa_strategy |
Method |
GET |
Content-Type |
application/json |
请求结构
GET /v2/ai_search/qa_strategy HTTP/1.1
HOST: qianfan.baidubce.com
Authorization: Bearer <AppBuilder API Key>
Content-Type: application/json
?offset=2&limit=4
参数名称 |
描述 |
Authorization |
AppBuilder API Key请前往控制台获取。 |
Query参数
参数名称 |
类型 |
是否必须 |
描述 |
config_id |
string |
是 |
配置ID。 |
offset |
string |
否 |
偏移量。 |
limit |
string |
否 |
条数限制,最大不超过50。 |
调用示例
curl --location 'https://qianfan.baidubce.com/v2/ai_search/qa_strategy?offset=2&limit=4' \
--header 'Content-Type: application/json' \
--header 'Authorization: <token>' \
响应参数
参数名称 |
类型 |
必填 |
描述 |
request_id |
string |
是 |
请求ID。 |
code |
string |
否 |
错误码,当发生异常时返回。 |
message |
string |
否 |
错误消息,当发生异常时返回。 |
count |
int |
是 |
结果总数。 |
items |
array<qa_strategy> |
是 |
问答策略数组。 |
+qa_strategy |
object |
是 |
问答策略。 |
++answer_strategy |
object |
是 |
回复策略。 |
++query_match_strategy |
object |
是 |
query匹配策略。 |
++query |
string |
是 |
query。 |
响应示例
{
"request_id": "123",
"count": 14,
"items": [{
"qa_strategy": {
"answer_strategy": {
"knowledge_base_answer_strategy_detail": null,
"name": "preset_answer",
"preset_answer_strategy_detail": {
"content": "今天黄金价格多少一克",
"references": [{
"content": " 快讯 美元指数再次冲高!金价小幅上涨!...",
"date": "2024-12-03",
"given_to_llm": true,
"icon": "https://appbuilder.bj.bcebos.com/baidu-search-rag-pro/icon/default.png",
"image_detail": {
"height": null,
"url": null,
"width": null
},
"ref_num": "1",
"resource_type": "web",
"title": "今天黄金价格多少一克_今日金价表_2024年金价多少钱...",
"url": "http://www.huangjinjiage.cn/",
"video": null,
"web_anchor": "金价查询网"
}]
}
},
"query_match_strategy": {
"name": "exact",
"similarity_threshold": 0.0
}
},
"query": "小米是组装厂吗"
}]
}