特定query干预
更新时间:2025-09-17
概述
在调用百度AI搜索API进行联网搜索总结时,可设置一系列特定的用户输入,通过完全匹配或者语义匹配的方式命中后,进行特定知识库检索后总结、特定知识库检索和联网搜索后总结、预置特定回答等方式进行输出,确保符合品牌立场、人设、形象,该接口仅支持智能搜索生成服务。
在调用该接口前:
- 准备好需要干预的输入清单。
- (可选)准备好对应不同输入的回答。
-
(可选)准备好对用不同输入需要参考进行回答的知识库,并准备好知识库ID。
新增问答策略
接口定义
URL | qianfan.baidubce.com/v2/ai_search/qa_strategy |
---|---|
Method | POST |
Content-Type | application/json |
请求结构
Plain Text
1POST /v2/ai_search/qa_strategy HTTP/1.1
2HOST: qianfan.baidubce.com
3Authorization: Bearer <AppBuilder API Key>
4Content-Type: application/json
5{
6 "query": "xx是组装厂吗?",
7 "config_id": "0035f63a-74fb-4615-b1ea-96f9e1f9ed55",
8 "query_match_strategy": {
9 "name": "keyword",
10 "keywords":["xx","组装厂"]
11 },
12 "answer_strategy": {
13 "name": "preset_answer",
14 "preset_answer_strategy_detail": {
15 "content": "xx不是组装厂",
16 "references": [ { } ]
17 }
18 }
19}
Header 参数
参数名称 | 描述 |
---|---|
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。 |
调用示例
Plain Text
1 curl --location 'https://qianfan.baidubce.com/v2/ai_search/qa_strategy' \
2 --header 'Content-Type: application/json' \
3 --header 'Authorization: <token>' \
4 --data '{ "query": "xx是组装厂吗?", "query_match_strategy": {"name": "keyword","keywords":[ "xx","组装厂"]}, "answer_strategy": {"name": "preset_answer",
5 "preset_answer_strategy_detail": {"content": "xx不是组装厂","references": [{}] } }}'
响应参数
参数名称 | 类型 | 描述 |
---|---|---|
request_id | string | 请求ID。 |
code | string | 错误码,当发生异常时返回。 |
message | string | 错误消息,当发生异常时返回。 |
响应示例
Plain Text
1{
2 "request_id": "123"
3}
删除问答策略
接口定义
URL | qianfan.baidubce.com/v2/ai_search/qa_strategy |
---|---|
Method | DELETE |
Content-Type | application/json |
请求结构
Plain Text
1 DELETE /v2/ai_search/qa_strategy HTTP/1.1
2 HOST: qianfan.baidubce.com
3 Authorization: Bearer <AppBuilder API Key>
4 Content-Type: application/json
5
6 ?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?
Header参数
参数名称 | 描述 |
---|---|
Authorization | AppBuilder API Key请前往控制台获取。 |
Query参数
参数名称 | 类型 | 是否必须 | 描述 |
---|---|---|---|
query | string | 是 | 需要对query进行urlencode。 |
config_id | string | 否 | 策略配置ID。 |
调用示例
Plain Text
1 curl -X "DELETE" \
2 -H "Authorization: <token> " \
3 --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 | 错误消息,当发生异常时返回。 |
响应示例
Plain Text
1{
2 "request_id": "123"
3}
分页查询问答策略
接口定义
URL | qianfan.baidubce.com/v2/ai_search/qa_strategy |
---|---|
Method | GET |
Content-Type | application/json |
请求结构
Plain Text
1 GET /v2/ai_search/qa_strategy HTTP/1.1
2 HOST: qianfan.baidubce.com
3 Authorization: Bearer <AppBuilder API Key>
4 Content-Type: application/json
5
6 ?offset=2&limit=4
Header参数
参数名称 | 描述 |
---|---|
Authorization | AppBuilder API Key请前往控制台获取。 |
Query参数
参数名称 | 类型 | 是否必须 | 描述 |
---|---|---|---|
config_id | string | 是 | 配置ID。 |
offset | string | 否 | 偏移量。 |
limit | string | 否 | 条数限制,最大不超过50。 |
调用示例
Plain Text
1 curl --location 'https://qianfan.baidubce.com/v2/ai_search/qa_strategy?offset=2&limit=4' \
2 --header 'Content-Type: application/json' \
3 --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。 |
响应示例
Plain Text
1 {
2 "request_id": "123",
3 "count": 14,
4 "items": [{
5 "qa_strategy": {
6 "answer_strategy": {
7 "knowledge_base_answer_strategy_detail": null,
8 "name": "preset_answer",
9 "preset_answer_strategy_detail": {
10 "content": "今天黄金价格多少一克",
11 "references": [{
12 "content": " 快讯 美元指数再次冲高!金价小幅上涨!...",
13 "date": "2024-12-03",
14 "given_to_llm": true,
15 "icon": "https://appbuilder.bj.bcebos.com/baidu-search-rag-pro/icon/default.png",
16 "image_detail": {
17 "height": null,
18 "url": null,
19 "width": null
20 },
21 "ref_num": "1",
22 "resource_type": "web",
23 "title": "今天黄金价格多少一克_今日金价表_2024年金价多少钱...",
24 "url": "http://www.huangjinjiage.cn/",
25 "video": null,
26 "web_anchor": "金价查询网"
27 }]
28 }
29 },
30 "query_match_strategy": {
31 "name": "exact",
32 "similarity_threshold": 0.0
33 }
34 },
35 "query": "小米是组装厂吗"
36 }]
37}