Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ML Model APIs #733

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added response schema for `PUT` and `DELETE /_plugins/_transform/{id}` ([#722](https://github.com/opensearch-project/opensearch-api-specification/pull/716))
- Added response schema for `GET /_plugins/_knn/warmup/{index}` ([#717](https://github.com/opensearch-project/opensearch-api-specification/pull/717))
- Added support for multiple test verbs ([#724](https://github.com/opensearch-project/opensearch-api-specification/pull/724))
- Added ML Model APIs `GET /_plugins/_ml/models/{}`, `POST /_plugins/_ml/models/_search`, and `PUT /_plugins/_ml/models/{}` to the spec along with the tests.
nathaliellenaa marked this conversation as resolved.
Show resolved Hide resolved
nathaliellenaa marked this conversation as resolved.
Show resolved Hide resolved

### 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
81 changes: 81 additions & 0 deletions spec/namespaces/ml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ paths:
'200':
$ref: '#/components/responses/ml.register_model@200'
/_plugins/_ml/models/{model_id}:
get:
operationId: ml.get_model.0
x-operation-group: ml.get_model
description: Retrieves a model.
parameters:
- $ref: '#/components/parameters/ml.get_model::path.model_id'
responses:
'200':
$ref: '#/components/responses/ml.get_model@200'
put:
operationId: ml.update_model.0
x-operation-group: ml.update_model
description: Updates a model.
parameters:
- $ref: '#/components/parameters/ml.update_model::path.model_id'
requestBody:
$ref: '#/components/requestBodies/ml.update_model'
responses:
'200':
$ref: '#/components/responses/ml.update_model@200'
delete:
operationId: ml.delete_model.0
x-operation-group: ml.delete_model
Expand Down Expand Up @@ -102,6 +122,15 @@ paths:
responses:
'200':
$ref: '#/components/responses/ml.search_models@200'
post:
nathaliellenaa marked this conversation as resolved.
Show resolved Hide resolved
operationId: ml.search_models.0
x-operation-group: ml.search_models
description: Searches for models.
requestBody:
$ref: '#/components/requestBodies/ml.search_models'
responses:
'200':
$ref: '#/components/responses/ml.search_models@200'
/_plugins/_ml/connectors/_create:
post:
operationId: ml.create_connector.0
Expand Down Expand Up @@ -212,6 +241,36 @@ components:
required:
- query
- size
ml.update_model:
content:
application/json:
schema:
type: object
properties:
connector:
type: object
description: The connector to use for the model.
connector_id:
type: string
description: The connector ID.
is_enabled:
type: boolean
description: Whether the model is enabled.
description:
type: string
description: The model description.
model_config:
$ref: '../schemas/ml._common.yaml#/components/schemas/ModelConfig'
name:
type: string
description: The model name.
rate_limiter:
$ref: '../schemas/ml._common.yaml#/components/schemas/RateLimiter'
guardrails:
$ref: '../schemas/ml._common.yaml#/components/schemas/Guardrails'
interface:
type: object
description: The model interface.
ml.create_connector:
content:
application/json:
Expand Down Expand Up @@ -325,6 +384,16 @@ components:
application/json:
schema:
$ref: '../schemas/_common.yaml#/components/schemas/WriteResponseBase'
ml.get_model@200:
content:
application/json:
schema:
$ref: '../schemas/ml._common.yaml#/components/schemas/Model'
ml.update_model@200:
content:
application/json:
schema:
$ref: '../schemas/ml._common.yaml#/components/schemas/UpdateModelResponse'
ml.delete_task@200:
content:
application/json:
Expand Down Expand Up @@ -385,6 +454,18 @@ components:
required: true
schema:
type: string
ml.get_model::path.model_id:
name: model_id
in: path
required: true
schema:
type: string
ml.update_model::path.model_id:
name: model_id
in: path
required: true
schema:
type: string
ml.deploy_model::path.model_id:
name: model_id
in: path
Expand Down
146 changes: 146 additions & 0 deletions spec/schemas/ml._common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,152 @@ components:
- description
- latest_version
- name
Model:
type: object
properties:
name:
type: string
description: The model name.
model_group_id:
type: string
description: The model group ID.
algorithm:
type: string
description: The algorithm.
model_version:
type: string
description: The model version.
model_format:
type: string
description: The model format.
enum:
- ONNX
- TORCH_SCRIPT
model_state:
type: string
description: The model state.
enum:
- DEPLOYED
- DEPLOYING
- DEPLOY_FAILED
- PARTIALLY_DEPLOYED
- REGISTERED
- REGISTERING
model_content_size_in_bytes:
type: integer
format: int64
description: The model content size in bytes.
model_content_hash_value:
type: string
description: The model content hash value.
model_config:
$ref: '#/components/schemas/ModelConfig'
created_time:
type: integer
format: int64
description: The created time.
last_updated_time:
type: integer
format: int64
description: The last updated time.
last_registered_time:
type: integer
format: int64
description: The last registered time.
total_chunks:
type: integer
format: int64
description: The total chunks.
is_hidden:
type: boolean
description: Whether the model is hidden.
required:
- model_state
RateLimiter:
type: object
properties:
limit:
type: integer
format: int64
description: The maximum limit.
unit:
type: string
description: The unit of time.
enum:
- DAYS
- HOURS
- MICROSECONDS
- MILLISECONDS
- MINUTES
- NANOSECONDS
- SECONDS
required:
- limit
- unit
Guardrails:
type: object
properties:
type:
type: string
description: The guardrails type.
enum:
- local_regex
- model
input_guardrail:
$ref: '#/components/schemas/GuardrailsInputOutput'
output_guardrail:
$ref: '#/components/schemas/GuardrailsInputOutput'
stop_words:
$ref: '_common.analysis.yaml#/components/schemas/StopWords'
index_name:
$ref: '_common.yaml#/components/schemas/IndexName'
source_fields:
$ref: '_common.yaml#/components/schemas/Fields'
regex:
type: object
description: The regex used for input/output validation.
model_id:
type: string
description: The model ID.
response_filter:
type: string
description: The response filter.
response_validation_regex:
type: string
description: The response validation regex.
GuardrailsInputOutput:
type: object
properties:
model_id:
type: string
description: The model ID.
response_validation_regex:
type: string
description: The response validation regex.
UpdateModelResponse:
type: object
properties:
_index:
$ref: '_common.yaml#/components/schemas/IndexName'
_id:
$ref: '_common.yaml#/components/schemas/Id'
_version:
$ref: '_common.yaml#/components/schemas/VersionNumber'
result:
$ref: '_common.yaml#/components/schemas/Result'
forced_refresh:
type: boolean
description: Whether the model is forced to refresh.
_shards:
$ref: '_common.yaml#/components/schemas/ShardStatistics'
_seq_no:
$ref: '_common.yaml#/components/schemas/SequenceNumber'
_primary_term:
type: integer
format: int64
description: The primary term.
required:
- _index
Task:
type: object
properties:
Expand Down
31 changes: 31 additions & 0 deletions tests/plugins/ml/ml/models.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,37 @@ chapters:
hits:
hits:
- _score: 1
- synopsis: Search model.
nathaliellenaa marked this conversation as resolved.
Show resolved Hide resolved
path: /_plugins/_ml/models/_search
method: POST
request:
payload:
query:
match_all: {}
size: 1000
response:
status: 200
payload:
hits:
hits:
- _score: 1
- synopsis: Get model.
path: /_plugins/_ml/models/{model_id}
method: GET
parameters:
model_id: ${get_completed_task.model_id}
response:
status: 200
- synopsis: Update model.
path: /_plugins/_ml/models/{model_id}
method: PUT
parameters:
model_id: ${get_completed_task.model_id}
request:
payload:
name: updated_name
nathaliellenaa marked this conversation as resolved.
Show resolved Hide resolved
response:
status: 200
- synopsis: Delete model.
path: /_plugins/_ml/models/{model_id}
parameters:
Expand Down
Loading