Skip to content

Commit

Permalink
Add ML Predict, Train APIs (#755)
Browse files Browse the repository at this point in the history
* Added ML predict and train APIs, updated CHANGELOG.

Signed-off-by: Nathalie Jonathan <[email protected]>

* Added ML train and predict API, fixed test for predict and train API, defined ML status as an enum, updated ML task state enum, updated CHANGELOG.md.

Signed-off-by: Nathalie Jonathan <[email protected]>

* Updated  examples to use books themed data, removed output from predict and train_predict API, fixed vale complaints.

Signed-off-by: Nathalie Jonathan <[email protected]>

* Removed excluded parts, changed files path.

Signed-off-by: Nathalie Jonathan <[email protected]>

---------

Signed-off-by: Nathalie Jonathan <[email protected]>
  • Loading branch information
nathaliellenaa authored Dec 31, 2024
1 parent 2c6502d commit a3849b4
Show file tree
Hide file tree
Showing 6 changed files with 565 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added support for combining output variables ([#737](https://github.com/opensearch-project/opensearch-api-specification/pull/737))
- Added 404 response to `/_search/scroll` ([#749](https://github.com/opensearch-project/opensearch-api-specification/pull/749))
- Added `node_failures` to `DELETE /_search/scroll` and `DELETE /_search/scroll/{scroll_id}` ([#749](https://github.com/opensearch-project/opensearch-api-specification/pull/749))
- Added `POST /_plugins/_ml/_train/{algorithm_name}`, `_predict/{algorithm_name}/{model_id}`, and `_train_predict/{algorithm_name}` ([#755](https://github.com/opensearch-project/opensearch-api-specification/pull/755))

### 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))
Expand Down
134 changes: 134 additions & 0 deletions spec/namespaces/ml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,43 @@ paths:
responses:
'200':
$ref: '#/components/responses/ml.search_models@200'
/_plugins/_ml/_predict/{algorithm_name}/{model_id}:
post:
operationId: ml.predict.0
x-operation-group: ml.predict
description: Predicts new data with trained model.
parameters:
- $ref: '#/components/parameters/ml.predict::path.algorithm_name'
- $ref: '#/components/parameters/ml.predict::path.model_id'
requestBody:
$ref: '#/components/requestBodies/ml.predict'
responses:
'200':
$ref: '#/components/responses/ml.predict@200'
/_plugins/_ml/_train/{algorithm_name}:
post:
operationId: ml.train.0
x-operation-group: ml.train
description: Trains a model synchronously.
parameters:
- $ref: '#/components/parameters/ml.train::path.algorithm_name'
requestBody:
$ref: '#/components/requestBodies/ml.train'
responses:
'200':
$ref: '#/components/responses/ml.train@200'
/_plugins/_ml/_train_predict/{algorithm_name}:
post:
operationId: ml.train_predict.0
x-operation-group: ml.train_predict
description: Trains a model and predicts against the same training dataset.
parameters:
- $ref: '#/components/parameters/ml.train_predict::path.algorithm_name'
requestBody:
$ref: '#/components/requestBodies/ml.train_predict'
responses:
'200':
$ref: '#/components/responses/ml.train_predict@200'
/_plugins/_ml/connectors/_create:
post:
operationId: ml.create_connector.0
Expand Down Expand Up @@ -212,6 +249,64 @@ components:
required:
- query
- size
ml.predict:
content:
application/json:
schema:
type: object
properties:
input_query:
$ref: '../schemas/ml._common.yaml#/components/schemas/InputQuery'
input_index:
type: array
items:
type: string
description: The input index.
text_docs:
type: array
items:
type: string
description: The text documents.
return_number:
type: boolean
description: Whether to return bytes in model output.
target_response:
type: array
items:
type: string
description: The target response.
ml.train:
content:
application/json:
schema:
type: object
properties:
parameters:
$ref: '../schemas/ml._common.yaml#/components/schemas/TrainParameters'
input_query:
$ref: '../schemas/ml._common.yaml#/components/schemas/InputQuery'
input_index:
type: array
description: The input index.
items:
type: string
ml.train_predict:
content:
application/json:
schema:
type: object
properties:
parameters:
$ref: '../schemas/ml._common.yaml#/components/schemas/TrainParameters'
input_query:
$ref: '../schemas/ml._common.yaml#/components/schemas/InputQuery'
input_index:
type: array
description: The input index.
items:
type: string
input_data:
$ref: '../schemas/ml._common.yaml#/components/schemas/PredictionResult'
ml.create_connector:
content:
application/json:
Expand Down Expand Up @@ -340,6 +435,21 @@ components:
application/json:
schema:
$ref: '../schemas/ml._common.yaml#/components/schemas/SearchModelsResponse'
ml.predict@200:
content:
application/json:
schema:
$ref: '../schemas/ml._common.yaml#/components/schemas/PredictResponse'
ml.train@200:
content:
application/json:
schema:
$ref: '../schemas/ml._common.yaml#/components/schemas/TrainResponse'
ml.train_predict@200:
content:
application/json:
schema:
$ref: '../schemas/ml._common.yaml#/components/schemas/TrainPredictResponse'
ml.create_connector@200:
content:
application/json:
Expand Down Expand Up @@ -403,6 +513,30 @@ components:
required: true
schema:
type: string
ml.predict::path.algorithm_name:
name: algorithm_name
in: path
required: true
schema:
type: string
ml.predict::path.model_id:
name: model_id
in: path
required: true
schema:
type: string
ml.train::path.algorithm_name:
name: algorithm_name
in: path
required: true
schema:
type: string
ml.train_predict::path.algorithm_name:
name: algorithm_name
in: path
required: true
schema:
type: string
ml.delete_connector::path.connector_id:
name: connector_id
in: path
Expand Down
Loading

0 comments on commit a3849b4

Please sign in to comment.