知识干预
更新时间:2025-03-27
1. 新增问答策略
接口描述
在调用百度AI搜索API进行联网搜索总结时,可设置一系列特定的用户输入,通过完全匹配、语义匹配或关键词匹配的方式命中后,进行特定知识库检索后总结、特定知识库检索+联网搜索后总结、预置特定回答等方式进行输出,确保符合品牌立场、人设、形象。
调用该接口前:
- 准备好需要干预的输入清单
- 准备好对应不同输入的回答(可选)
- 准备好对不同输入进行回答需要参考的知识库,并准备好知识库ID(可选)
- 在AppBuilder页面进行创建知识库
- 通过OpenAPI进行创建知识库
接口定义
URL | https://qianfan.baidubce.com/v2/ai_search/qa_strategy |
---|---|
Method | POST |
Content-Type | application/json |
请求参数
字段 | 类型 | 是否必填 | 说明 |
---|---|---|---|
query | str | 是 | 问答query,不超过256个字符 |
query_match_strategy | QueryMatchStrategy | 是 | query匹配策略 |
answer_strategy | AnswerStrategy | 是 | 回复策略 |
QueryMatchStrategy对象
字段 | 类型 | 必填 | 说明 |
---|---|---|---|
name | string | 是 | 匹配策略名字:exact - 完全匹配semantic - 语义匹配keyword - 关键词匹配 |
similarity_threshold | float | 否 | 当语义匹配时,该字段会被用到,值介于0~1之间,默认0.9 |
embedding | array |
否 | 当语义匹配时,该字段会被用到 |
keywords | array |
否 | 当关键词匹配时,该字段会被用到,范围为0~256 |
AnswerStrategy对象
字段 | 类型 | 必填 | 说明 |
---|---|---|---|
name | string | 是 | 回复策略。 preset_answer - 预置答案 baidusearch_and_knowledge_base - 参考百度搜索知识库进行回答 knowledge_base - 知识库 |
preset_answer_strategy_detail | PresetAnswerStrategyDetail | 否 | 预置回答策略 |
knowledge_base_answer_strategy_detail | KnowledgeBaseAnswerStrategyDetail | 否 | 知识库回答策略 |
AnswerStrategy.PresetAnswerStrategyDetail
字段 | 类型 | 必填 | 说明 |
---|---|---|---|
content | string | 是 | 预设答案内容 |
references | array[reference] | 是 | 参考信息来源。 (格式和百度AI搜索的响应参数中的Reference对象一致) |
AnswerStrategy.KnowledgeBaseAnswerStrategyDetail
字段 | 类型 | 必填 | 说明 |
---|---|---|---|
knowledge_base_ids | array |
是 | 知识库id数组 |
document_ids | array |
是 | 文档id数组 |
top_k | int | 否 | 最相关的前k个结果,默认top6 |
响应参数
字段 | 类型 | 必填 | 说明 |
---|---|---|---|
request_id | string | 是 | 请求request_id |
code | string | 否 | 错误代码,当发生异常时返回 |
message | string | 否 | 错误消息,当发生异常时返回 |
请求示例
Plain Text
1curl --location 'https://qianfan.baidubce.com/v2/ai_search/qa_strategy' \
2--header 'Content-Type: application/json' \
3--header 'Authorization: Bearer authorization string' \
4--data '{
5 "query": "xx是组装厂吗?",
6 "query_match_strategy": {
7 "name": "keyword",
8 "keywords": [
9 "xx", "组装厂"
10 ]
11 },
12 "answer_strategy": {
13 "name": "preset_answer",
14 "preset_answer_strategy_detail": {
15 "content": "xx不是组装厂",
16 "references": []
17 }
18 }
19}'
响应示例
Plain Text
1{"request_id": "123"}
2. 删除问答策略
接口描述
删除问答策略
接口定义
URL | https://qianfan.baidubce.com/v2/ai_search/qa_strategy |
---|---|
Method | DELETE |
Content-Type | application/json |
请求参数
字段名 | 字段类型 | 是否必须 | 说明 |
---|---|---|---|
query | str | 是 | 待删除的问答策略匹配query |
响应参数
字段 | 类型 | 必填 | 说明 |
---|---|---|---|
request_id | string | 是 | 请求request_id |
code | string | 否 | 错误代码,当发生异常时返回 |
message | string | 否 | 错误消息,当发生异常时返回 |
请求示例
Plain Text
1curl -X "DELETE" \
2--header 'Authorization: Bearer authorization string' \
3--location 'https://qianfan.baidubce.com/v2/ai_search/qa_strategy?query=%E5%B0**E5%90%97%EF%BC%9F'
响应示例
Plain Text
1{"request_id": "123"}
3. 分页查询问答策略
接口定义
URL | https://qianfan.baidubce.com/v2/ai_search/qa_strategy |
---|---|
Method | GET |
Content-Type | application/json |
请求params入参
字段名 | 字段类型 | 是否必须 | 说明 |
---|---|---|---|
offset | str | 否 | 偏移量 |
limit | str | 否 | 条数限制,最大不超过50 |
响应参数
字段 | 类型 | 必填 | 描述 |
---|---|---|---|
request_id | string | 是 | 请求request_id |
code | string | 否 | 错误代码,当发生异常时返回 |
message | string | 否 | 错误消息,当发生异常时返回 |
count | int | 是 | 结果总数 |
items | array<qa_strategy> | 是 | 问答策略数组 |
qa_strategy对象
字段 | 类型 | 说明 |
---|---|---|
answer_strategy | object | 回复策略 |
query_match_strategy | object | query匹配策略 |
query | string | query |
请求示例
Plain Text
1curl --location 'https://qianfan.baidubce.com/v2/ai_search/qa_strategy?offset=2&limit=4' \
2--header 'Content-Type: application/json' \
3--header 'Authorization: Bearer authorization string' \
响应示例
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": "今天xx价格多钱",
11 "references": [{
12 "content": "快讯 美元指数再次冲高!金价小幅上涨!...",
13 "date": "2024-12-03",
14 "given_to_llm": true,
15 "icon": "https://appbuilder.bj.bcebos.com/baidu-searag-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": "今天xx价格多少多少钱...",
24 "url": "http://www.hgjinjiage.cn/",
25 "video": null,
26 "web_anchor": "xx查询网"
27 }]
28 }
29 },
30 "query_match_strategy": {
31 "name": "exact",
32 "similarity_threshold": 0.0
33 },
34 "query": "xx是组装厂吗"
35 }
36 }]
37}