Link Search Menu Expand Document Documentation Menu

创建异常检测器工具

2.16 版本引入

这是一个实验性功能,不建议在生产环境中使用。有关该功能的进度更新或如果您想留下反馈,请参阅相关的 GitHub 问题

CreateAnomalyDetectorTool 根据您提供的索引帮助创建异常检测器。此工具检索索引映射,并使大型语言模型 (LLM) 能够推荐类别字段、聚合字段及其相应的聚合方法,这些都是 Create Anomaly Detector API 所必需的。

有关异常检测器的全面信息,请参阅异常检测

步骤 1:注册一个运行 CreateAnomalyDetectorTool 的流代理

流代理按顺序运行一系列工具,返回最后一个工具的输出。要创建流代理,请发送以下注册代理请求

POST /_plugins/_ml/agents/_register
{
  "name": "Test_Agent_For_Create_Anomaly_Detector_Tool",
  "type": "flow",
  "description": "this is a test agent for the CreateAnomalyDetectorTool",
  "memory": {
    "type": "demo"
  },
  "tools": [
      {
      "type": "CreateAnomalyDetectorTool",
      "name": "DemoCreateAnomalyDetectorTool",
      "parameters": {
        "model_id": "<the model id of LLM>"
      }
    }
  ]
}

OpenSearch 将返回一个代理 ID,例如,如下所示

{
  "agent_id": "EuJYYo0B9RaBCvhuy1q8"
}

步骤 2:运行代理

通过发送以下请求来运行代理

POST /_plugins/_ml/agents/EuJYYo0B9RaBCvhuy1q8/_execute
{
  "parameters": {
    "index": "sample_weblogs_test"
  }
}

OpenSearch 将返回一个 JSON 字符串,其中包含创建异常检测器所有推荐参数,例如以下示例响应中所示的字符串

{
  "inference_results": [
    {
      "output": [
        {
          "name": "response",
          "result":"""{"index":"sample_weblogs_test","categoryField":"ip.keyword","aggregationField":"bytes,response,responseLatency","aggregationMethod":"sum,avg,avg","dateFields":"utc_time,timestamp"}"""
        }
      ]
    }
  ]
}

然后,您可以发送类似以下内容的请求,创建一个包含推荐参数的异常检测器

POST _plugins/_anomaly_detection/detectors
{
  "name": "test-detector",
  "description": "Test detector",
  "time_field": "timestamp",
  "indices": [
    "sample_weblogs_test"
  ],
  "feature_attributes": [
    {
      "feature_name": "feature_bytes",
      "feature_enabled": true,
      "aggregation_query": {
        "agg1": {
          "sum": {
            "field": "bytes"
          }
        }
      }
    },
    {
      "feature_name": "feature_response",
      "feature_enabled": true,
      "aggregation_query": {
        "agg2": {
          "avg": {
            "field": "response"
          }
        }
      }
    },
    {
      "feature_name": "feature_responseLatency",
      "feature_enabled": true,
      "aggregation_query": {
        "agg3": {
          "avg": {
            "field": "responseLatency"
          }
        }
      }
    }
  ],
  "detection_interval": {
    "period": {
      "interval": 1,
      "unit": "Minutes"
    }
  },
  "window_delay": {
    "period": {
      "interval": 1,
      "unit": "Minutes"
    }
  }
}

注册参数

下表列出了代理注册可用的工具参数。

参数 类型 必需/可选 描述
model_id 字符串 必需 用于建议所需的 Create Anomaly Detector API 参数的 LLM 模型 ID。
model_type 字符串 可选 模型类型。有效值为 CLAUDE (Anthropic Claude 模型) 和 OPENAI (OpenAI 模型)。

执行参数

下表列出了运行代理可用的工具参数。

参数 类型 必需/可选 描述
index 字符串 必需 索引名称。支持通配符(例如,weblogs-*)。如果使用通配符,则该工具从第一个解析的索引中获取映射并将其发送给 LLM。
剩余 350 字符

有问题?

想做贡献?