品牌保护问答策略配置
更新时间:2025-06-18
概述
在调用百度AI搜索API进行联网搜索总结时,可设置一系列特定的用户输入,通过完全匹配或者语义匹配的方式命中后,进行特定知识库检索后总结、特定知识库检索+联网搜索后总结、预置特定回答等方式进行输出,确保符合品牌立场、人设、形象,该接口仅支持智能搜索生成服务。
在调用该接口前:
- 准备好需要干预的输入清单
- 准备好对应不同输入的回答(可选)
-
准备好对用不同输入需要参考进行回答的知识库,并准备好知识库ID(可选)
新增问答策略
接口定义
URL | https://qianfan.baidubce.com/v2/ai_search/qa_strategy |
---|---|
Method | POST |
Content-Type | 无 |
请求结构
Plain Text
1POST /v2/ai_search/qa_strategy HTTP/1.1HOST: qianfan.baidubce.comAuthorization: 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": [ { } ] } }}
Header 参数
参数名称 | 描述 |
---|---|
Content-Type | 参数值:application/json |
Authorization | XXXXX 为appbuider-token,请前往获取https://console.bce.baidu.com/ai_apaas/secretKey |
请求参数
参数名称 | 类型 | 是否必填 | 描述 |
---|---|---|---|
query | str | 是 | 问答query,不超过 25 6个字符 |
config_id | str | 否 | 策略配置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.knowledge_base_answer_strategy_detail对象
参数名称 | 类型 | 是否必填 | 描述 |
---|---|---|---|
knowledge_base_ids | array<string> | 是 | 知识库id数组 |
document_ids | array<string> | 是 | 文档id数组 |
top_k | int | 否 | 最相关的前k个结果,默认top6 |
调用示例
Plain Text
1 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 | 是 | 请求request_id |
code | string | 否 | 错误代码,当发生异常时返回 |
message | string | 否 | 错误消息,当发生异常时返回 |
响应示例
Plain Text
1{"request_id": "123"}
删除问答策略
接口定义
URL | https://qianfan.baidubce.com/v2/ai_search/qa_strategy |
---|---|
Method | DELETE |
Content-Type | 无 |
请求结构
Plain Text
1 DELETE /v2/ai_search/qa_strategy HTTP/1.1HOST: qianfan.baidubce.comAuthorization: Bearer <AppBuilder API Key>Content-Type: application/jsonquery=%E5%B0%8F%E7%B1%B3%E6%98%AF%E7%BB%84%E8%A3%85%E5%8E%82%E5%90%97%EF%BC%9F?
Header参数
参数名称 | 说明 |
---|---|
Authorization | XXXXX为appbuider-token,请前往获取https://console.bce.baidu.com/ai_apaas/secretKey |
请求params入参
参数名称 | 类型 | 是否必须 | 描述 |
---|---|---|---|
query | str | 是 | 需要对query进行urlencode |
config_id | str | 否 | 策略配置id,需要提前调用配置接口创建id |
调用示例
Plain Text
1 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 | 是 | 请求request_id |
code | string | 否 | 错误代码,当发生异常时返回 |
message | string | 否 | 错误消息,当发生异常时返回 |
响应示例
Plain Text
1{"request_id": "123"}
分页查询问答策略
接口定义
URL | https://qianfan.baidubce.com/v2/ai_search/qa_strategy |
---|---|
Method | GET |
Content-Type | 无 |
请求结构
Plain Text
1 GET /v2/ai_search/qa_strategy HTTP/1.1HOST: qianfan.baidubce.comAuthorization: Bearer <AppBuilder API Key>Content-Type: application/json?offset=2&limit=4
Header参数
参数名称 | 描述 |
---|---|
Authorization | XXXXX为appbuider-token,请前往获取https://console.bce.baidu.com/ai_apaas/secretKey |
请求params入参
参数名称 | 类型 | 是否必须 | 描述 |
---|---|---|---|
offset | str | 否 | 偏移量 |
limit | str | 否 | 条数限制,最大不超过 50 |
config_id | str | 是 | 配置id |
调用示例
Plain Text
1 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 | 是 | 请求request_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 |
响应示例
Plain Text
1 { "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": "小米是组装厂吗" }]}