搜索异常结果工具
2.13 版本引入
SearchAnomalyResultsTool
工具检索有关异常检测器结果的信息。有关异常检测器的更多信息,请参阅异常检测。
步骤 1:注册一个将运行 SearchAnomalyResultsTool 的流代理
流代理按顺序运行一系列工具,并返回最后一个工具的输出。要创建流代理,请发送以下注册代理请求:
POST /_plugins/_ml/agents/_register
{
"name": "Test_Agent_For_Search_Anomaly_Results_Tool",
"type": "flow",
"description": "this is a test agent for the SearchAnomalyResultsTool",
"memory": {
"type": "demo"
},
"tools": [
{
"type": "SearchAnomalyResultsTool",
"name": "DemoSearchAnomalyResultsTool",
"parameters": {}
}
]
}
有关参数描述,请参阅注册参数。
OpenSearch 返回一个代理 ID
{
"agent_id": "HuJZYo0B9RaBCvhuUlpy"
}
步骤 2:运行代理
通过发送以下请求来运行代理
POST /_plugins/_ml/agents/HuJZYo0B9RaBCvhuUlpy/_execute
{
"parameters": {
"question": "Do I have any anomalies?"
}
}
OpenSearch 返回集群上设置的单个异常检测器列表(每个结果包含检测器 ID、异常等级和置信水平)以及找到的异常结果总数
{
"inference_results": [
{
"output": [
{
"name": "response",
"result": "AnomalyResults=[{detectorId=ef9lYo0Bk4MTqircmjnm,grade=1.0,confidence=0.9403051246569198}{detectorId=E-JlYo0B9RaBCvhunFtw,grade=1.0,confidence=0.9163498216870274}]TotalAnomalyResults=2"
}
]
}
]
}
如果未发现异常,OpenSearch 将在结果中返回一个空数组
{
"inference_results": [
{
"output": [
{
"name": "response",
"result": "AnomalyResults=[]TotalAnomalyResults=0"
}
]
}
]
}
注册参数
下表列出了注册代理时可用的所有工具参数。所有参数都是可选的。
参数 | 类型 | 描述 |
---|---|---|
detectorId | 字符串 | 要返回结果的检测器 ID。 |
realTime | 布尔型 | 是否返回实时异常检测器结果。将此参数设置为 false 以仅返回历史分析结果。 |
anomalyGradeThreshold | 浮点型 | 返回的异常检测器结果的最小异常等级。异常等级是介于 0 到 1 之间的数字,表示数据点的异常程度。 |
dataStartTime | 长整型 | 要返回异常检测器结果的最早时间,以毫秒为单位。 |
dataEndTime | 长整型 | 要返回异常检测器结果的最晚时间,以毫秒为单位。 |
sortOrder | 字符串 | 结果的排序顺序。有效值为 asc (升序)和 desc (降序)。默认值为 desc 。 |
sortString | 字符串 | 指定用于排序结果的检测器字段。默认值为 data_start_time 。 |
size | 整数 | 要返回的结果数量。默认值为 20 。 |
startIndex | 整数 | 要开始的分页结果索引。默认值为 0 。 |
执行参数
下表列出了运行代理时可用的所有工具参数。
参数 | 类型 | 必需/可选 | 描述 |
---|---|---|---|
question | 字符串 | 必需 | 要发送到 LLM 的自然语言问题。 |