Retail V2 API - Class Google::Cloud::Retail::V2::ModelService::Client (v0.21.0)

Reference documentation and code samples for the Retail V2 API class Google::Cloud::Retail::V2::ModelService::Client.

Client for the ModelService service.

Service for performing CRUD operations on models. Recommendation models contain all the metadata necessary to generate a set of models for the Predict() API. A model is queried indirectly via a ServingConfig, which associates a model with a given Placement (e.g. Frequently Bought Together on Home Page).

This service allows you to do the following:

  • Initiate training of a model.
  • Pause training of an existing model.
  • List all the available models along with their metadata.
  • Control their tuning schedule.

Inherits

  • Object

Methods

.configure

def self.configure() { |config| ... } -> Client::Configuration

Configure the ModelService Client class.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter
Example
# Modify the configuration for all ModelService clients
::Google::Cloud::Retail::V2::ModelService::Client.configure do |config|
  config.timeout = 10.0
end

#configure

def configure() { |config| ... } -> Client::Configuration

Configure the ModelService Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on Client.configure.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter

#create_model

def create_model(request, options = nil) -> ::Gapic::Operation
def create_model(parent: nil, model: nil, dry_run: nil) -> ::Gapic::Operation

Creates a new model.

Overloads
def create_model(request, options = nil) -> ::Gapic::Operation
Pass arguments to create_model via a request object, either of type CreateModelRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Retail::V2::CreateModelRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def create_model(parent: nil, model: nil, dry_run: nil) -> ::Gapic::Operation
Pass arguments to create_model via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. The parent resource under which to create the model. Format: projects/{project_number}/locations/{location_id}/catalogs/{catalog_id}
  • model (::Google::Cloud::Retail::V2::Model, ::Hash) — Required. The payload of the Model to create.
  • dry_run (::Boolean) — Optional. Whether to run a dry run to validate the request (without actually creating the model).
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)
Returns
  • (::Gapic::Operation)
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/retail/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Retail::V2::ModelService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Retail::V2::CreateModelRequest.new

# Call the create_model method.
result = client.create_model request

# The returned object is of type Gapic::Operation. You can use it to
# check the status of an operation, cancel it, or wait for results.
# Here is how to wait for a response.
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "No response received."
end

#delete_model

def delete_model(request, options = nil) -> ::Google::Protobuf::Empty
def delete_model(name: nil) -> ::Google::Protobuf::Empty

Deletes an existing model.

Overloads
def delete_model(request, options = nil) -> ::Google::Protobuf::Empty
Pass arguments to delete_model via a request object, either of type DeleteModelRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Retail::V2::DeleteModelRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def delete_model(name: nil) -> ::Google::Protobuf::Empty
Pass arguments to delete_model via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameter
  • name (::String) — Required. The resource name of the Model to delete. Format: projects/{project_number}/locations/{location_id}/catalogs/{catalog_id}/models/{model_id}
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/retail/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Retail::V2::ModelService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Retail::V2::DeleteModelRequest.new

# Call the delete_model method.
result = client.delete_model request

# The returned object is of type Google::Protobuf::Empty.
p result

#get_model

def get_model(request, options = nil) -> ::Google::Cloud::Retail::V2::Model
def get_model(name: nil) -> ::Google::Cloud::Retail::V2::Model

Gets a model.

Overloads
def get_model(request, options = nil) -> ::Google::Cloud::Retail::V2::Model
Pass arguments to get_model via a request object, either of type GetModelRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Retail::V2::GetModelRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def get_model(name: nil) -> ::Google::Cloud::Retail::V2::Model
Pass arguments to get_model via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameter
  • name (::String) — Required. The resource name of the Model to get. Format: projects/{project_number}/locations/{location_id}/catalogs/{catalog}/models/{model_id}
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/retail/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Retail::V2::ModelService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Retail::V2::GetModelRequest.new

# Call the get_model method.
result = client.get_model request

# The returned object is of type Google::Cloud::Retail::V2::Model.
p result

#initialize

def initialize() { |config| ... } -> Client

Create a new ModelService client object.

Yields
  • (config) — Configure the ModelService client.
Yield Parameter
Returns
  • (Client) — a new instance of Client
Example
# Create a client using the default configuration
client = ::Google::Cloud::Retail::V2::ModelService::Client.new

# Create a client using a custom configuration
client = ::Google::Cloud::Retail::V2::ModelService::Client.new do |config|
  config.timeout = 10.0
end

#list_models

def list_models(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Retail::V2::Model>
def list_models(parent: nil, page_size: nil, page_token: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Retail::V2::Model>

Lists all the models linked to this event store.

Overloads
def list_models(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Retail::V2::Model>
Pass arguments to list_models via a request object, either of type ListModelsRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Retail::V2::ListModelsRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def list_models(parent: nil, page_size: nil, page_token: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Retail::V2::Model>
Pass arguments to list_models via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. The parent for which to list models. Format: projects/{project_number}/locations/{location_id}/catalogs/{catalog_id}
  • page_size (::Integer) — Optional. Maximum number of results to return. If unspecified, defaults to 50. Max allowed value is 1000.
  • page_token (::String) — Optional. A page token, received from a previous ListModels call. Provide this to retrieve the subsequent page.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Returns
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/retail/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Retail::V2::ModelService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Retail::V2::ListModelsRequest.new

# Call the list_models method.
result = client.list_models request

# The returned object is of type Gapic::PagedEnumerable. You can iterate
# over elements, and API calls will be issued to fetch pages as needed.
result.each do |item|
  # Each element is of type ::Google::Cloud::Retail::V2::Model.
  p item
end

#location_client

def location_client() -> Google::Cloud::Location::Locations::Client

Get the associated client for mix-in of the Locations.

Returns
  • (Google::Cloud::Location::Locations::Client)

#operations_client

def operations_client() -> ::Google::Cloud::Retail::V2::ModelService::Operations

Get the associated client for long-running operations.

#pause_model

def pause_model(request, options = nil) -> ::Google::Cloud::Retail::V2::Model
def pause_model(name: nil) -> ::Google::Cloud::Retail::V2::Model

Pauses the training of an existing model.

Overloads
def pause_model(request, options = nil) -> ::Google::Cloud::Retail::V2::Model
Pass arguments to pause_model via a request object, either of type PauseModelRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Retail::V2::PauseModelRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def pause_model(name: nil) -> ::Google::Cloud::Retail::V2::Model
Pass arguments to pause_model via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameter
  • name (::String) — Required. The name of the model to pause. Format: projects/{project_number}/locations/{location_id}/catalogs/{catalog_id}/models/{model_id}
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/retail/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Retail::V2::ModelService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Retail::V2::PauseModelRequest.new

# Call the pause_model method.
result = client.pause_model request

# The returned object is of type Google::Cloud::Retail::V2::Model.
p result

#resume_model

def resume_model(request, options = nil) -> ::Google::Cloud::Retail::V2::Model
def resume_model(name: nil) -> ::Google::Cloud::Retail::V2::Model

Resumes the training of an existing model.

Overloads
def resume_model(request, options = nil) -> ::Google::Cloud::Retail::V2::Model
Pass arguments to resume_model via a request object, either of type ResumeModelRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Retail::V2::ResumeModelRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def resume_model(name: nil) -> ::Google::Cloud::Retail::V2::Model
Pass arguments to resume_model via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameter
  • name (::String) — Required. The name of the model to resume. Format: projects/{project_number}/locations/{location_id}/catalogs/{catalog_id}/models/{model_id}
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/retail/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Retail::V2::ModelService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Retail::V2::ResumeModelRequest.new

# Call the resume_model method.
result = client.resume_model request

# The returned object is of type Google::Cloud::Retail::V2::Model.
p result

#tune_model

def tune_model(request, options = nil) -> ::Gapic::Operation
def tune_model(name: nil) -> ::Gapic::Operation

Tunes an existing model.

Overloads
def tune_model(request, options = nil) -> ::Gapic::Operation
Pass arguments to tune_model via a request object, either of type TuneModelRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Retail::V2::TuneModelRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def tune_model(name: nil) -> ::Gapic::Operation
Pass arguments to tune_model via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameter
  • name (::String) — Required. The resource name of the model to tune. Format: projects/{project_number}/locations/{location_id}/catalogs/{catalog_id}/models/{model_id}
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)
Returns
  • (::Gapic::Operation)
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/retail/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Retail::V2::ModelService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Retail::V2::TuneModelRequest.new

# Call the tune_model method.
result = client.tune_model request

# The returned object is of type Gapic::Operation. You can use it to
# check the status of an operation, cancel it, or wait for results.
# Here is how to wait for a response.
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "No response received."
end

#universe_domain

def universe_domain() -> String

The effective universe domain

Returns
  • (String)

#update_model

def update_model(request, options = nil) -> ::Google::Cloud::Retail::V2::Model
def update_model(model: nil, update_mask: nil) -> ::Google::Cloud::Retail::V2::Model

Update of model metadata. Only fields that currently can be updated are: filtering_option and periodic_tuning_state. If other values are provided, this API method ignores them.

Overloads
def update_model(request, options = nil) -> ::Google::Cloud::Retail::V2::Model
Pass arguments to update_model via a request object, either of type UpdateModelRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Retail::V2::UpdateModelRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def update_model(model: nil, update_mask: nil) -> ::Google::Cloud::Retail::V2::Model
Pass arguments to update_model via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/retail/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Retail::V2::ModelService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Retail::V2::UpdateModelRequest.new

# Call the update_model method.
result = client.update_model request

# The returned object is of type Google::Cloud::Retail::V2::Model.
p result