diff --git a/CHANGELOG.md b/CHANGELOG.md index 1065fe451..3cb728001 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added `GET`, `POST`, `PUT`, `DELETE /_plugins/_ml/controllers/{model_id}` ([#779](https://github.com/opensearch-project/opensearch-api-specification/pull/779)) - Added `GET /_plugins/_ml/profile`, `GET /_plugins/_ml/profile/models`, `models/{model_id}`, `tasks`, `tasks/{task_id}` ([#787](https://github.com/opensearch-project/opensearch-api-specification/pull/787)) - Added `GET /_plugins/_ml/stats/`, `stats/{stat}`, `{nodeId}/stats/`, `{nodeId}/stats/{stat}` ([#794](https://github.com/opensearch-project/opensearch-api-specification/pull/794)) +- Added `GET`, `POST /_plugins/_ml/tasks/_search`, `GET /_plugins/_ml/tools`, `tools/{tool_name}` ([#797](https://github.com/opensearch-project/opensearch-api-specification/pull/797)) ### Removed - Removed unsupported `_common.mapping:SourceField`'s `mode` field and associated `_common.mapping:SourceFieldMode` enum ([#652](https://github.com/opensearch-project/opensearch-api-specification/pull/652)) diff --git a/spec/namespaces/ml.yaml b/spec/namespaces/ml.yaml index ca4d8be26..a5775127b 100644 --- a/spec/namespaces/ml.yaml +++ b/spec/namespaces/ml.yaml @@ -270,6 +270,7 @@ paths: get: operationId: ml.get_task.0 x-operation-group: ml.get_task + x-version-added: '1.3' description: Retrieves a task. parameters: - $ref: '#/components/parameters/ml.get_task::path.task_id' @@ -279,12 +280,34 @@ paths: delete: operationId: ml.delete_task.0 x-operation-group: ml.delete_task + x-version-added: '1.3' description: Deletes a task. parameters: - $ref: '#/components/parameters/ml.delete_task::path.task_id' responses: '200': $ref: '#/components/responses/ml.delete_task@200' + /_plugins/_ml/tasks/_search: + get: + operationId: ml.search_tasks.0 + x-operation-group: ml.search_tasks + x-version-added: '1.3' + description: Searches for tasks. + requestBody: + $ref: '#/components/requestBodies/ml.search_tasks' + responses: + '200': + $ref: '#/components/responses/ml.search_tasks@200' + post: + operationId: ml.search_tasks.1 + x-operation-group: ml.search_tasks + x-version-added: '1.3' + description: Searches for tasks. + requestBody: + $ref: '#/components/requestBodies/ml.search_tasks' + responses: + '200': + $ref: '#/components/responses/ml.search_tasks@200' /_plugins/_ml/models/_search: get: operationId: ml.search_models.0 @@ -735,6 +758,26 @@ paths: responses: '200': $ref: '#/components/responses/ml.get_stats@200' + /_plugins/_ml/tools: + get: + operationId: ml.get_tools.0 + x-operation-group: ml.get_tools + x-version-added: '2.12' + description: Get tools. + responses: + '200': + $ref: '#/components/responses/ml.get_tools@200' + /_plugins/_ml/tools/{tool_name}: + get: + operationId: ml.get_tools.1 + x-operation-group: ml.get_tools + x-version-added: '2.12' + description: Get tools. + parameters: + - $ref: '#/components/parameters/ml.get_tools::path.tool_name' + responses: + '200': + $ref: '#/components/responses/ml.get_tools@200' components: requestBodies: ml.register_model_group: @@ -1038,6 +1081,23 @@ components: description: The text documents. required: - text_docs + ml.search_tasks: + content: + application/json: + schema: + type: object + properties: + query: + $ref: '../schemas/ml._common.yaml#/components/schemas/Query' + size: + type: integer + format: int64 + description: The number of tasks to return. + sort: + type: array + items: + $ref: '../schemas/ml._common.yaml#/components/schemas/Sort' + description: The sort order. ml.predict: content: application/json: @@ -1520,6 +1580,11 @@ components: application/json: schema: $ref: '../schemas/ml._common.yaml#/components/schemas/Task' + ml.search_tasks@200: + content: + application/json: + schema: + $ref: '../schemas/ml._common.yaml#/components/schemas/SearchTasksResponse' ml.search_models@200: content: application/json: @@ -1741,6 +1806,15 @@ components: application/json: schema: $ref: '../schemas/ml._common.yaml#/components/schemas/GetStatsResponse' + ml.get_tools@200: + content: + application/json: + schema: + oneOf: + - type: array + items: + $ref: '../schemas/ml._common.yaml#/components/schemas/GetToolsResponse' + - $ref: '../schemas/ml._common.yaml#/components/schemas/GetToolsResponse' parameters: ml.get_all_memories::query.max_results: name: max_results @@ -2047,4 +2121,28 @@ components: in: path required: true schema: - type: string \ No newline at end of file + type: string + ml.get_tools::path.tool_name: + name: tool_name + in: path + required: true + schema: + type: string + enum: + - AgentTool + - CatIndexTool + - ConnectorTool + - CreateAnomalyDetectorTool + - IndexMappingTool + - LogPatternTool + - MLModelTool + - NeuralSparseSearchTool + - PPLTool + - RAGTool + - SearchAlertsTool + - SearchAnomalyDetectorsTool + - SearchAnomalyResultsTool + - SearchIndexTool + - SearchMonitorsTool + - VectorDBTool + - VisualizationTool \ No newline at end of file diff --git a/spec/schemas/ml._common.yaml b/spec/schemas/ml._common.yaml index 97bef40b4..edc648e60 100644 --- a/spec/schemas/ml._common.yaml +++ b/spec/schemas/ml._common.yaml @@ -6,6 +6,8 @@ info: paths: {} components: schemas: + SearchTasksResponse: + $ref: '#/components/schemas/SearchResponse' SearchModelsResponse: $ref: '#/components/schemas/SearchResponse' SearchResponse: @@ -144,6 +146,10 @@ components: type: integer format: int64 description: The last updated time. + last_update_time: + type: integer + format: int64 + description: The last update time. last_registered_time: type: integer format: int64 @@ -211,8 +217,11 @@ components: format: date-time description: The updated time. create_time: - type: string - format: date-time + anyOf: + - type: string + format: date-time + - type: integer + format: int64 description: The create time. application_type: type: ['null', string] @@ -242,6 +251,42 @@ components: prompt_template: type: ['null', string] description: The prompt template. + is_async: + type: boolean + description: Whether the task is asynchronous. + function_name: + $ref: '#/components/schemas/FunctionName' + input_type: + type: string + description: The input type. + enum: + - DATA_FRAME + - QUESTION_ANSWERING + - REMOTE + - SEARCH_QUERY + - TEXT_DOCS + - TEXT_SIMILARITY + worker_node: + type: array + items: + $ref: '_common.yaml#/components/schemas/NodeIds' + task_type: + type: string + description: Task type. + enum: + - BATCH_INGEST + - BATCH_PREDICTION + - DEPLOY_MODEL + - EXECUTION + - PREDICTION + - REGISTER_MODEL + - TRAINING + - TRAINING_AND_PREDICTION + state: + $ref: '#/components/schemas/Status' + error: + type: string + description: The error message. ModelConfig: type: object properties: @@ -483,6 +528,8 @@ components: type: array items: $ref: '_common.yaml#/components/schemas/Id' + function_name: + $ref: '#/components/schemas/FunctionName' model_id: $ref: '_common.yaml#/components/schemas/Name' name: @@ -494,28 +541,30 @@ components: description: The algorithm. properties: value: - type: string - description: The function name. - enum: - - AD_LIBSVM - - AGENT - - ANOMALY_LOCALIZATION - - BATCH_RCF - - CONNECTOR - - FIT_RCF - - KMEANS - - LINEAR_REGRESSION - - LOCAL_SAMPLE_CALCULATOR - - LOGISTIC_REGRESSION - - METRICS_CORRELATION - - QUESTION_ANSWERING - - RCF_SUMMARIZE - - REMOTE - - SAMPLE_ALGO - - SPARSE_ENCODING - - SPARSE_TOKENIZE - - TEXT_EMBEDDING - - TEXT_SIMILARITY + $ref: '#/components/schemas/FunctionName' + FunctionName: + type: string + description: The function name. + enum: + - AD_LIBSVM + - AGENT + - ANOMALY_LOCALIZATION + - BATCH_RCF + - CONNECTOR + - FIT_RCF + - KMEANS + - LINEAR_REGRESSION + - LOCAL_SAMPLE_CALCULATOR + - LOGISTIC_REGRESSION + - METRICS_CORRELATION + - QUESTION_ANSWERING + - RCF_SUMMARIZE + - REMOTE + - SAMPLE_ALGO + - SPARSE_ENCODING + - SPARSE_TOKENIZE + - TEXT_EMBEDDING + - TEXT_SIMILARITY OwnerNameKeyword: type: object description: The owner name keyword. @@ -919,10 +968,16 @@ components: type: string description: Task type. enum: + - BATCH_INGEST + - BATCH_PREDICTION - DEPLOY_MODEL + - EXECUTION + - PREDICTION - REGISTER_MODEL + - TRAINING + - TRAINING_AND_PREDICTION function_name: - type: string + $ref: '#/components/schemas/FunctionName' worker_node: type: array items: @@ -1262,15 +1317,17 @@ components: format: int64 description: The estimated memory size in GPU. deploy: - $ref: '#/components/schemas/Deploy' + $ref: '#/components/schemas/ModelStats' register: - $ref: '#/components/schemas/Register' + $ref: '#/components/schemas/ModelStats' undeploy: - $ref: '#/components/schemas/Undeploy' + $ref: '#/components/schemas/ModelStats' predict: - $ref: '#/components/schemas/Predict' + $ref: '#/components/schemas/ModelStats' train: - $ref: '#/components/schemas/Train' + $ref: '#/components/schemas/ModelStats' + train_predict: + $ref: '#/components/schemas/ModelStats' PredictRequestStats: type: object properties: @@ -1402,15 +1459,17 @@ components: type: object properties: deploy: - $ref: '#/components/schemas/Deploy' + $ref: '#/components/schemas/ModelStats' register: - $ref: '#/components/schemas/Register' + $ref: '#/components/schemas/ModelStats' undeploy: - $ref: '#/components/schemas/Undeploy' + $ref: '#/components/schemas/ModelStats' predict: - $ref: '#/components/schemas/Predict' + $ref: '#/components/schemas/ModelStats' train: - $ref: '#/components/schemas/Train' + $ref: '#/components/schemas/ModelStats' + train_predict: + $ref: '#/components/schemas/ModelStats' ModelStats: type: object properties: @@ -1426,13 +1485,25 @@ components: type: integer format: int64 description: The executing task count. - Deploy: - $ref: '#/components/schemas/ModelStats' - Register: - $ref: '#/components/schemas/ModelStats' - Undeploy: - $ref: '#/components/schemas/ModelStats' - Predict: - $ref: '#/components/schemas/ModelStats' - Train: - $ref: '#/components/schemas/ModelStats' + Aggregation: + type: object + properties: + sum: + $ref: '#/components/schemas/Aggregation' + field: + type: string + description: The field name. + additionalProperties: true + GetToolsResponse: + type: object + properties: + name: + $ref: '_common.yaml#/components/schemas/Name' + description: + type: string + description: The tool description. + type: + type: string + description: The tool type. + version: + $ref: '_common.yaml#/components/schemas/VersionString' \ No newline at end of file diff --git a/tests/plugins/ml/ml/tasks/search.yaml b/tests/plugins/ml/ml/tasks/search.yaml new file mode 100644 index 000000000..21b0fba4a --- /dev/null +++ b/tests/plugins/ml/ml/tasks/search.yaml @@ -0,0 +1,58 @@ +$schema: ../../../../../json_schemas/test_story.schema.yaml + +description: Test the search of tasks. +version: '>= 2.7' +prologues: + - path: /_cluster/settings + method: PUT + request: + payload: + persistent: + plugins.ml_commons.jvm_heap_memory_threshold: 100 + - path: /_plugins/_ml/models/_register + id: register_model + method: POST + request: + payload: + name: test_kmeans_model + function_name: KMEANS + model_format: TORCH_SCRIPT + output: + task_id: payload.task_id +epilogues: + - path: /_plugins/_ml/tasks/{task_id} + method: DELETE + status: [200, 404] + parameters: + task_id: ${register_model.task_id} +chapters: + - synopsis: Search task. + path: /_plugins/_ml/tasks/_search + method: GET + request: + payload: + query: + match_all: {} + size: 1000 + response: + status: 200 + payload: + hits: + hits: + - _score: 1 + - synopsis: Search task with function name. + path: /_plugins/_ml/tasks/_search + method: POST + request: + payload: + query: + bool: + filter: + - term: + function_name: KMEANS + response: + status: 200 + payload: + hits: + hits: + - _score: 0 \ No newline at end of file diff --git a/tests/plugins/ml/ml/tools.yaml b/tests/plugins/ml/ml/tools.yaml new file mode 100644 index 000000000..c09abb42b --- /dev/null +++ b/tests/plugins/ml/ml/tools.yaml @@ -0,0 +1,17 @@ +$schema: ../../../../json_schemas/test_story.schema.yaml + +description: Test the retrieval of tools. +version: '>= 2.12' +chapters: + - synopsis: Get tools. + path: /_plugins/_ml/tools + method: GET + response: + status: 200 + - synopsis: Get tools by tool name. + path: /_plugins/_ml/tools/{tool_name} + method: GET + parameters: + tool_name: ConnectorTool + response: + status: 200 \ No newline at end of file