知识问答API支持接入安全审核,在通用参数中可以通过设置green_net为true来开启安全审核,安全审核在知识问答链路中分为两步,第一步是对输入的问题内容进行安全合规方面的审核,如问题内容不符合安全规范,api会响应相应的错误信息,第二步是对模型生成的回答进行安全合规方面的审核,目前流式回答每10个字送检一次,如模型回答不符合安全规范,同样api会响应的错误信息,注意流式对话和非流式对话会响应错误信息会存在不同的结果格式,具体格式参考下文详细说明。
通用参数
请求入参
一级参数 | 说明 | 类型 | 是否必传 |
input | 给大模型的相关信息 | {} | 是 |
parameters | 大模型参数 | {} | 是 |
debug | debug模式 | boolean | 是,默认为false |
一级参数 | 二级参数 | 说明 | 类型 | 是否必传 | 默认值 |
input | session_id | 对话的上下文id,空则新建对话 | string | 连续对话必传 | "" |
prompts | 提问问题 | string | 是 | ||
plugin_schemas | 插件参数 | {} | |||
max_tokens | 输出最大token数 | int | 否 | 512 | |
stream | 是否流式对话 | boolean | 否 | true | |
tenant_id | 标识search服务 | string | 是 | 固定值"msearch" | |
app_id | 服务id | long | 是 | ||
system_prompt | 预设指令 | string | 否 | "" | |
green_net | 安全审核 | boolean | 否 | false | |
parameters | top_p | 模型的核采样值 | float | 否 | 0.7 |
top_k | 模型采样范围大小 | int | 否 | 50 | |
temperature | 采样温度 | int | 否 | 1 | |
allow_direct_answer | 是否开启大模型 | boolean | 否 | true | |
num_doc | 参与summary的doc数量 | int | 否 | 3 | |
tp_search | 是否强制搜索 | string | 否 | "" | |
tp_query_rewrite | 是否进行query改写 | string | 否 | "" | |
content_fields | 用于引用信息拼接,多个字段使用分隔符"," | string | 否 | "" | |
reject_templete | 拒识模板 | string | 否 | "" | |
max_cotent_length | 单条知识长度上限(50~2000)且num_docs * max_content_length<=6000 | int | 否 | 1000 |
二级参数 | 三级参数 | 四级参数 | 说明 | 类型 | 是否必传 | 默认值 |
plugin_schemas | search_enhance | vector_recall_ratio | 向量召回比例(0.1~0.9) | float | 否 | 0.7 |
acc_sorting | 精排doc数量(50~500) | int | 否 | 200 | ||
custom_sorting | 自定义排序参数 | {} | 否 | "" | ||
search_size | 单query召回数量 | int | 否 | 3 | ||
custom_config_info | 自定义搜索配置 | {} | 否 | |||
filters | 筛选参数配置 | [] | 否 | |||
fields | 召回字段(正排)多个字段使用分隔符"," | string | 否 | "" |
响应参数
非流式对话:返回是一个标准的http响应,其中data字段包含了chat的返回数据
一级参数 | 二级参数 | 说明 |
data | content | chat的回答内容 |
attachment | 当前搜索对话的参考文献,搜索推荐等 | |
session_id | 当前对话的上下文信息 | |
item_id | 系统内部自动生成的id,用于debug | |
hasRisk | 模型回答内容是否存在敏感内容
|
二级参数 | 三级参数 | 说明 |
attachment | refer | 当前回答的引用信息 |
search_recommend | 下一步对话搜索推荐 | |
content_fields | 用于引用信息拼接 | |
fields | 用于判断引用信息的主键(默认第一个) | |
debug | debug 模式会增加 debug 字段,具体内容参考流式对话 |
问题输入存在违规内容:
{
"code" : 8004,
"data" : "问题包含敏感信息",
"httpStatusCode" : 200,
"msg" : "问题包含敏感信息",
"requestId" : "4A930161-3BA8-406A-A76C-540F8B98DCA2",
"success" : true
}
模型回答存在违规内容
{
"code" : 8001,
"data" : {
"attachment" : {
"content_fields" : [
"id",
"gmt_create",
"gmt_modified",
"file_name",
"file_type",
"url"
],
"debug" : {
"child_execs" : [
{
"end_time" : 1705397334081,
"exec_kind" : "AI_FLOW_STEP",
"exec_name" : "search_toggle",
"exec_params" : {
"api_key" : "sk-f******46de",
"history_messages" : [
],
"max_new_tokens" : 512,
"model_id" : "daily-top_qad-392",
"query" : "阿里云峰会",
"stream" : false,
"system_prompt" : "",
"top_p" : 0.69999999999999996,
"tp_search" : ""
},
"exec_result" : {
"do_search" : true
},
"exec_status" : true,
"start_time" : 1705397333671,
"trace_id" : "AD6E0C1B-E5DE-488C-BCC9-D2CA08CDEC0D"
},
{
"end_time" : 1705397334676,
"exec_kind" : "AI_FLOW_STEP",
"exec_name" : "search_rewrite",
"exec_params" : {
"api_key" : "sk-f******46de",
"history_messages" : [
],
"max_new_tokens" : 512,
"model_id" : "daily-top_qad-392",
"query" : "阿里云峰会",
"stream" : false,
"system_prompt" : "",
"top_p" : 0.69999999999999996,
"tp_query_rewrite" : ""
},
"exec_result" : {
"queries_r" : [
"阿里云峰会"
]
},
"exec_status" : true,
"start_time" : 1705397334081,
"trace_id" : "AD6E0C1B-E5DE-488C-BCC9-D2CA08CDEC0D"
},
{
"end_time" : 1705397335075,
"exec_kind" : "AI_FLOW_STEP",
"exec_name" : "search",
"exec_params" : {
"customConfigInfo" : {
"rerankSize" : 200,
"uqVectorRecallRatio" : 0.5
},
"fields" : [
"id",
"gmt_create",
"gmt_modified",
"file_name",
"file_type",
"url"
],
"page" : 1,
"rankModelInfo" : {
"default" : {
"aggregate_algo" : "weight_avg",
"features" : [
{
"name" : "vector_index",
"norm" : true,
"norm_factor" : 0.00050000000000000001,
"score_type" : "L2",
"threshold" : 0,
"weights" : 1
},
{
"field" : "_rc_t_score",
"name" : "static_value",
"norm" : true,
"threshold" : 0,
"weights" : 0.5
}
]
}
},
"rid" : "AD6E0C1B-E5DE-488C-BCC9-D2CA08CDEC0D",
"rows" : 3,
"scene" : "dolphin_search_ms_index_es_1743_pre",
"type" : "file_name,file_type,url,id,vector",
"uq" : "阿里云峰会"
},
"exec_result" : {
"code" : 200,
"data" : {
"data" : {
"docs" : [
{
"_id" : "1_10",
"_q_score" : 1,
"_rc_score" : 1,
"_rc_t_score" : 5.5928690000000003,
"_rc_v_score" : 0.55256680000000002,
"_score" : 1.4981447458267212,
"_scores" : {
"static_value(_rc_t_score)" : 0.49814474582672119,
"vector_index" : 1
},
"file_name" : "0- 阿里云峰会_逍遥子.pdf",
"file_type" : "pdf",
"gmt_create" : "2024-01-09 16:43:07",
"gmt_modified" : "2024-01-10 16:32:46",
"id" : 1,
"url" : "oss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf"
},
{
"_id" : "1_4",
"_q_score" : 1,
"_rc_score" : 1,
"_rc_t_score" : 5.5928690000000003,
"_rc_v_score" : 0.55708396000000004,
"_score" : 1.4981447458267212,
"_scores" : {
"static_value(_rc_t_score)" : 0.49814474582672119,
"vector_index" : 1
},
"file_name" : "0- 阿里云峰会_逍遥子.pdf",
"file_type" : "pdf",
"gmt_create" : "2024-01-09 16:43:07",
"gmt_modified" : "2024-01-10 16:32:46",
"id" : 1,
"url" : "oss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf"
},
{
"_id" : "1_20",
"_q_score" : 1,
"_rc_score" : 1,
"_rc_t_score" : 5.5928690000000003,
"_rc_v_score" : 0.53299249999999998,
"_score" : 1.4981447458267212,
"_scores" : {
"static_value(_rc_t_score)" : 0.49814474582672119,
"vector_index" : 1
},
"file_name" : "0- 阿里云峰会_逍遥子.pdf",
"file_type" : "pdf",
"gmt_create" : "2024-01-09 16:43:07",
"gmt_modified" : "2024-01-10 16:32:46",
"id" : 1,
"url" : "oss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf"
}
],
"keywords" : [
{
"fuzzy" : true,
"name" : "全文",
"schema" : "file_name,file_type,url,id",
"value" : "阿里云峰会"
}
],
"qpInfos" : [
{
"cleanQuery" : "阿里云峰会",
"operator" : "AND",
"query" : "阿里云峰会",
"recognitions" : [
],
"rewrite" : "阿里云峰会",
"sensitive" : false,
"spellcheck" : false,
"spellchecked" : "阿里云峰会",
"stopWords" : [
],
"synonymWords" : [
],
"tokenized" : [
"阿里云",
"峰会"
]
}
],
"total" : 27,
"totalDistinct" : 27
},
"headers" : {
"__d_head_engine_rt" : "q:194-s:[t116,v116]-r:4-i:18",
"__d_head_es_rt" : "t:12",
"__d_head_rtm" : "1705397335069",
"__d_head_sip" : "192.169.X.XXX",
"__d_head_ver" : "0.0.1"
},
"rid" : "AD6E0C1B-E5DE-488C-BCC9-D2CA08CDEC0D",
"status" : 0,
"success" : true
},
"httpStatusCode" : 200,
"requestId" : "AD6E0C1B-E5DE-488C-BCC9-D2CA08CDEC0D",
"success" : true
},
"exec_status" : true,
"start_time" : 1705397334676,
"trace_id" : "AD6E0C1B-E5DE-488C-BCC9-D2CA08CDEC0D"
},
{
"end_time" : 1705397337929,
"exec_kind" : "AI_FLOW_STEP",
"exec_name" : "search_recommend",
"exec_params" : {
"api_key" : "sk-f******46de",
"history_messages" : [
{
"content" : "阿里云峰会",
"role" : "user"
},
{
"content" : "根据提供的搜索结果,阿里云峰会的演讲文件可以被称为“阿里云峰会_逍遥子.pdf”,该文件的存储位置在吉林移动搜索云的oss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf [1][2][3]。",
"role" : "assistant"
}
],
"max_new_tokens" : 512,
"model_id" : "daily-top_qad-392",
"stream" : false,
"system_prompt" : "",
"top_p" : 0.69999999999999996
},
"exec_result" : {
"queries_s" : [
"阿里云峰会是什么?",
"有哪些重要的演讲者?",
"峰会的主题是什么?"
]
},
"exec_status" : true,
"start_time" : 1705397336739,
"trace_id" : "AD6E0C1B-E5DE-488C-BCC9-D2CA08CDEC0D"
}
],
"exec_kind" : "AI_FLOW",
"exec_name" : "corp_search_v2.json",
"exec_params" : {
"async_run" : false,
"debug" : true,
"flow_json_url" : "https://******/corp_search_v2.json",
"flow_params" : {
"allow_direct_answer" : true,
"api_key" : "sk-f******46de",
"content_fields" : "id,gmt_create,gmt_modified,file_name,file_type,url",
"custom_config_info" : "{\"rerankSize\": 200, \"uqVectorRecallRatio\": 0.5}",
"fields" : "id,gmt_create,gmt_modified,file_name,file_type,url",
"human_input" : "阿里云峰会",
"max_content_length" : 1000,
"max_new_tokens" : 512,
"num_doc" : 3,
"rank_model_info" : "{\"default\": {\"features\": [{\"name\": \"vector_index\", \"weights\": 1, \"threshold\": 0, \"norm\": true, \"norm_factor\": 0.0005, \"score_type\": \"L2\"}, {\"name\": \"static_value\", \"field\": \"_rc_t_score\", \"weights\": 0.5, \"threshold\": 0, \"norm\": true}], \"aggregate_algo\": \"weight_avg\"}}",
"reject_template" : "",
"scene" : "dolphin_search_ms_index_es_1743_pre",
"search_size" : 3,
"system_input" : "",
"temperature" : 1,
"top_k" : 50,
"top_p" : 0.69999999999999996,
"tp_query_rewrite" : "",
"tp_search" : "",
"type" : "file_name,file_type,url,id,vector"
},
"round_id" : "f-r-6ShmeWG46UEMTVho34YBTv",
"session_id" : "f-s-WztQqCTsSrBSbtyPSa9qWB",
"streaming" : false
},
"exec_result" : {
"ext" : {
},
"prompt" : "{\"query\": \"阿里云峰会\", \"model_id\": \"daily-top_qad-392\", \"api_key\": \"sk-f******46de\", \"stream\": false, \"search_results\": [{\"id\": 1, \"content\": \"1\\n2024-01-09 16:43:07\\n2024-01-10 16:32:46\\n0- 阿里云峰会_逍遥子.pdf\\npdf\\noss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf\", \"raw_search_result\": {\"gmt_create\": \"2024-01-09 16:43:07\", \"_rc_v_score\": 0.5525668, \"file_name\": \"0- 阿里云峰会_逍遥子.pdf\", \"_q_score\": 1.0, \"gmt_modified\": \"2024-01-10 16:32:46\", \"_score\": 1.4981447458267212, \"url\": \"oss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf\", \"_rc_score\": 1.0, \"_rc_t_score\": 5.592869, \"_scores\": {\"vector_index\": 1.0, \"static_value(_rc_t_score)\": 0.4981447458267212}, \"file_type\": \"pdf\", \"id\": 1, \"_id\": \"1_10\"}}, {\"id\": 2, \"content\": \"1\\n2024-01-09 16:43:07\\n2024-01-10 16:32:46\\n0- 阿里云峰会_逍遥子.pdf\\npdf\\noss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf\", \"raw_search_result\": {\"gmt_create\": \"2024-01-09 16:43:07\", \"_rc_v_score\": 0.55708396, \"file_name\": \"0- 阿里云峰会_逍遥子.pdf\", \"_q_score\": 1.0, \"gmt_modified\": \"2024-01-10 16:32:46\", \"_score\": 1.4981447458267212, \"url\": \"oss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf\", \"_rc_score\": 1.0, \"_rc_t_score\": 5.592869, \"_scores\": {\"vector_index\": 1.0, \"static_value(_rc_t_score)\": 0.4981447458267212}, \"file_type\": \"pdf\", \"id\": 1, \"_id\": \"1_4\"}}, {\"id\": 3, \"content\": \"1\\n2024-01-09 16:43:07\\n2024-01-10 16:32:46\\n0- 阿里云峰会_逍遥子.pdf\\npdf\\noss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf\", \"raw_search_result\": {\"gmt_create\": \"2024-01-09 16:43:07\", \"_rc_v_score\": 0.5329925, \"file_name\": \"0- 阿里云峰会_逍遥子.pdf\", \"_q_score\": 1.0, \"gmt_modified\": \"2024-01-10 16:32:46\", \"_score\": 1.4981447458267212, \"url\": \"oss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf\", \"_rc_score\": 1.0, \"_rc_t_score\": 5.592869, \"_scores\": {\"vector_index\": 1.0, \"static_value(_rc_t_score)\": 0.4981447458267212}, \"file_type\": \"pdf\", \"id\": 1, \"_id\": \"1_20\"}}], \"history_messages\": [], \"seed\": 1705397335, \"system_prompt\": \"\", \"temperature\": 1.0, \"top_p\": 0.7, \"top_k\": 50, \"length_penalty\": 1.0, \"num_doc\": 3, \"answer_doc\": false, \"max_new_tokens\": 512, \"tp_answer\": \"\", \"allow_direct_answer\": true, \"max_content_length\": 1000, \"reject_template\": \"\"}",
"result" : [
"根据提供的搜索结果,阿里云峰会的演讲文件可以被称为“阿里云峰会_逍遥子.pdf”,该文件的存储位置在吉林移动搜索云的oss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf [1][2][3]。"
]
},
"exec_status" : true,
"start_time" : 1705397333669,
"trace_id" : "AD6E0C1B-E5DE-488C-BCC9-D2CA08CDEC0D"
},
"fields" : [
"id",
"gmt_create",
"gmt_modified",
"file_name",
"file_type",
"url"
],
"refer" : [
{
"file_name" : "0- 阿里云峰会_逍遥子.pdf",
"file_type" : "pdf",
"gmt_create" : "2024-01-09 16:43:07",
"gmt_modified" : "2024-01-10 16:32:46",
"id" : 1,
"score" : 1.4981447458267212,
"url" : "oss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf"
},
{
"file_name" : "0- 阿里云峰会_逍遥子.pdf",
"file_type" : "pdf",
"gmt_create" : "2024-01-09 16:43:07",
"gmt_modified" : "2024-01-10 16:32:46",
"id" : 1,
"score" : 1.4981447458267212,
"url" : "oss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf"
},
{
"file_name" : "0- 阿里云峰会_逍遥子.pdf",
"file_type" : "pdf",
"gmt_create" : "2024-01-09 16:43:07",
"gmt_modified" : "2024-01-10 16:32:46",
"id" : 1,
"score" : 1.4981447458267212,
"url" : "oss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf"
}
],
"search_recommend" : [
"阿里云峰会是什么?",
"有哪些重要的演讲者?",
"峰会的主题是什么?"
]
},
"content" : "**文字里可能包含敏感信息**",
"hasRisk" : true,
"item_id" : "f-r-6ShmeWG46UEMTVho34YBTv",
"session_id" : "f-s-WztQqCTsSrBSbtyPSa9qWB"
},
"httpStatusCode" : 200,
"msg" : "**文字里可能包含敏感信息**",
"requestId" : "AD6E0C1B-E5DE-488C-BCC9-D2CA08CDEC0D",
"success" : true
}
流式对话
问题输入存在违规内容
id:system
event:error
data:{"errorCode":8004,"errorMsg":"问题包含敏感信息","data":"问题包含敏感信息"}
retry:3000
模型回答存在违规内容
id:system
event:open
data:success
retry:3000
id:85712A88-4BA3-45C1-A6F7-A346F4BCDA86
event:control
data:{"attachment":{"ext":null,"payload":{"do_search":true},"name":"search_toggle"},"item_id":"f-r-G43qdUWdN2VVwFe5ecLJsJ","session_id":"f-s-jmnBcTDqNMKUUsGwHMXhfS","content":"search_toggle"}
retry:3000
id:85712A88-4BA3-45C1-A6F7-A346F4BCDA86
event:control
data:{"attachment":{"ext":null,"payload":{"queries_r":["阿里云峰会"]},"name":"search_rewrite"},"item_id":"f-r-G43qdUWdN2VVwFe5ecLJsJ","session_id":"f-s-jmnBcTDqNMKUUsGwHMXhfS","content":"search_rewrite"}
retry:3000
id:85712A88-4BA3-45C1-A6F7-A346F4BCDA86
event:control
data:{"attachment":{"ext":null,"payload":{"refer":[{"gmt_create":"2024-01-09 16:43:07","score":1.4981447458267212,"file_name":"0- 阿里云峰会_逍遥子.pdf","file_type":"pdf","id":1,"gmt_modified":"2024-01-10 16:32:46","url":"oss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf"},{"gmt_create":"2024-01-09 16:43:07","score":1.4981447458267212,"file_name":"0- 阿里云峰会_逍遥子.pdf","file_type":"pdf","id":1,"gmt_modified":"2024-01-10 16:32:46","url":"oss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf"},{"gmt_create":"2024-01-09 16:43:07","score":1.4981447458267212,"file_name":"0- 阿里云峰会_逍遥子.pdf","file_type":"pdf","id":1,"gmt_modified":"2024-01-10 16:32:46","url":"oss://msearch-cloud-jilin/dz_test/testDir/0- 阿里云峰会_逍遥子.pdf"}],"uq":"阿里云峰会"},"name":"search"},"item_id":"f-r-G43qdUWdN2VVwFe5ecLJsJ","session_id":"f-s-jmnBcTDqNMKUUsGwHMXhfS","content":"search"}
retry:3000
id:85712A88-4BA3-45C1-A6F7-A346F4BCDA86
event:message
data:{"attachment":null,"item_id":"f-r-G43qdUWdN2VVwFe5ecLJsJ","session_id":"f-s-jmnBcTDqNMKUUsGwHMXhfS","content":"根据提供的搜"}
retry:3000
id:system
event:error
data:{"errorCode":8001,"errorMsg":"**文字里可能包含敏感信息**","data":"**文字里可能包含敏感信息**"}
retry:3000
id:system
event:close
data:success
retry:3000