Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
feat(samples): add feature values apis samples (#341)
Browse files Browse the repository at this point in the history
* added create-featurestore-sample.js and create-featurestore-sample.test.js

* feat(samples): added createFeaturestore sample (#313)

* feat(samples): added remaining featurestore samples (#313)

* removed the extraneous files

* feat(samples): add feature-values apis samples (#313)

* feat(samples): add feature values apis samples (#313)

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* feat(samples): update dependency featurevalues apis (#313)

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: junkourata <102059808+junkourata@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 4, 2022
1 parent 90dcec7 commit 4cef015
Show file tree
Hide file tree
Showing 9 changed files with 961 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-ai-platform
| Sample | Source Code | Try it |
| --------------------------- | --------------------------------- | ------ |
| Batch-create-features-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/batch-create-features-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/batch-create-features-sample.js,samples/README.md) |
| Batch-read-feature-values-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/batch-read-feature-values-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/batch-read-feature-values-sample.js,samples/README.md) |
| Cancel-batch-prediction-job | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/cancel-batch-prediction-job.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/cancel-batch-prediction-job.js,samples/README.md) |
| Cancel-custom-job | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/cancel-custom-job.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/cancel-custom-job.js,samples/README.md) |
| Create-batch-prediction-job-text-classification | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/create-batch-prediction-job-text-classification.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/create-batch-prediction-job-text-classification.js,samples/README.md) |
Expand Down Expand Up @@ -121,6 +122,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-ai-platform
| Delete-model | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/delete-model.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/delete-model.js,samples/README.md) |
| Deploy-model-custom-trained-model | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/deploy-model-custom-trained-model.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/deploy-model-custom-trained-model.js,samples/README.md) |
| Deploy-model | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/deploy-model.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/deploy-model.js,samples/README.md) |
| Export-feature-values-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/export-feature-values-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/export-feature-values-sample.js,samples/README.md) |
| Export-feature-values-snapshot-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/export-feature-values-snapshot-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/export-feature-values-snapshot-sample.js,samples/README.md) |
| Export-model-tabular-classification | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/export-model-tabular-classification.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/export-model-tabular-classification.js,samples/README.md) |
| Export-model | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/export-model.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/export-model.js,samples/README.md) |
| Get-batch-prediction-job | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/get-batch-prediction-job.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/get-batch-prediction-job.js,samples/README.md) |
Expand Down Expand Up @@ -152,6 +155,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-ai-platform
| Import-data-video-classification | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/import-data-video-classification.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/import-data-video-classification.js,samples/README.md) |
| Import-data-video-object-tracking | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/import-data-video-object-tracking.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/import-data-video-object-tracking.js,samples/README.md) |
| Import-data | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/import-data.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/import-data.js,samples/README.md) |
| Import-feature-values-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/import-feature-values-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/import-feature-values-sample.js,samples/README.md) |
| List-endpoints | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/list-endpoints.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/list-endpoints.js,samples/README.md) |
| List-entity-types-async-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/list-entity-types-async-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/list-entity-types-async-sample.js,samples/README.md) |
| List-entity-types-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/list-entity-types-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/list-entity-types-sample.js,samples/README.md) |
Expand All @@ -172,6 +176,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-ai-platform
| Predict-text-entity-extraction | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/predict-text-entity-extraction.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/predict-text-entity-extraction.js,samples/README.md) |
| Predict-text-sentiment-analysis | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/predict-text-sentiment-analysis.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/predict-text-sentiment-analysis.js,samples/README.md) |
| Quickstart | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |
| Read-feature-values-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/read-feature-values-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/read-feature-values-sample.js,samples/README.md) |
| Search-features-async-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/search-features-async-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/search-features-async-sample.js,samples/README.md) |
| Search-features-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/search-features-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/search-features-sample.js,samples/README.md) |
| Search-features-stream-sample | [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/search-features-stream-sample.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/search-features-stream-sample.js,samples/README.md) |
Expand Down
90 changes: 90 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ machine learning development lifecycle.
* [Before you begin](#before-you-begin)
* [Samples](#samples)
* [Batch-create-features-sample](#batch-create-features-sample)
* [Batch-read-feature-values-sample](#batch-read-feature-values-sample)
* [Cancel-batch-prediction-job](#cancel-batch-prediction-job)
* [Cancel-custom-job](#cancel-custom-job)
* [Create-batch-prediction-job-text-classification](#create-batch-prediction-job-text-classification)
Expand Down Expand Up @@ -59,6 +60,8 @@ machine learning development lifecycle.
* [Delete-model](#delete-model)
* [Deploy-model-custom-trained-model](#deploy-model-custom-trained-model)
* [Deploy-model](#deploy-model)
* [Export-feature-values-sample](#export-feature-values-sample)
* [Export-feature-values-snapshot-sample](#export-feature-values-snapshot-sample)
* [Export-model-tabular-classification](#export-model-tabular-classification)
* [Export-model](#export-model)
* [Get-batch-prediction-job](#get-batch-prediction-job)
Expand Down Expand Up @@ -90,6 +93,7 @@ machine learning development lifecycle.
* [Import-data-video-classification](#import-data-video-classification)
* [Import-data-video-object-tracking](#import-data-video-object-tracking)
* [Import-data](#import-data)
* [Import-feature-values-sample](#import-feature-values-sample)
* [List-endpoints](#list-endpoints)
* [List-entity-types-async-sample](#list-entity-types-async-sample)
* [List-entity-types-sample](#list-entity-types-sample)
Expand All @@ -110,6 +114,7 @@ machine learning development lifecycle.
* [Predict-text-entity-extraction](#predict-text-entity-extraction)
* [Predict-text-sentiment-analysis](#predict-text-sentiment-analysis)
* [Quickstart](#quickstart)
* [Read-feature-values-sample](#read-feature-values-sample)
* [Search-features-async-sample](#search-features-async-sample)
* [Search-features-sample](#search-features-sample)
* [Search-features-stream-sample](#search-features-stream-sample)
Expand Down Expand Up @@ -153,6 +158,23 @@ __Usage:__



### Batch-read-feature-values-sample

View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/batch-read-feature-values-sample.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/batch-read-feature-values-sample.js,samples/README.md)

__Usage:__


`node samples/batch-read-feature-values-sample.js`


-----




### Cancel-batch-prediction-job

View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/cancel-batch-prediction-job.js).
Expand Down Expand Up @@ -884,6 +906,40 @@ __Usage:__



### Export-feature-values-sample

View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/export-feature-values-sample.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/export-feature-values-sample.js,samples/README.md)

__Usage:__


`node samples/export-feature-values-sample.js`


-----




### Export-feature-values-snapshot-sample

View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/export-feature-values-snapshot-sample.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/export-feature-values-snapshot-sample.js,samples/README.md)

__Usage:__


`node samples/export-feature-values-snapshot-sample.js`


-----




### Export-model-tabular-classification

View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/export-model-tabular-classification.js).
Expand Down Expand Up @@ -1411,6 +1467,23 @@ __Usage:__



### Import-feature-values-sample

View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/import-feature-values-sample.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/import-feature-values-sample.js,samples/README.md)

__Usage:__


`node samples/import-feature-values-sample.js`


-----




### List-endpoints

View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/list-endpoints.js).
Expand Down Expand Up @@ -1751,6 +1824,23 @@ __Usage:__



### Read-feature-values-sample

View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/read-feature-values-sample.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-ai-platform&page=editor&open_in_editor=samples/read-feature-values-sample.js,samples/README.md)

__Usage:__


`node samples/read-feature-values-sample.js`


-----




### Search-features-async-sample

View the [source code](https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/search-features-async-sample.js).
Expand Down
136 changes: 136 additions & 0 deletions samples/batch-read-feature-values-sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Batch reads Feature values from a Featurestore.
* See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running
* the code snippet
*/

'use strict';

async function main(
project,
featurestoreId,
inputCsvFile,
destinationTableUri,
location = 'us-central1',
apiEndpoint = 'us-central1-aiplatform.googleapis.com',
timeout = 300000
) {
// [START aiplatform_batch_read_feature_values_sample]
/**
* TODO(developer): Uncomment these variables before running the sample.\
* (Not necessary if passing values as arguments)
*/

// const project = 'YOUR_PROJECT_ID';
// const featurestoreId = 'YOUR_FEATURESTORE_ID';
// const inputCsvFile = 'YOUR_INPUT_CSV_FILE_URI';
// const destinationTableUri = 'YOUR_BQ_DESTINATION_TABLE_URI';
// const location = 'YOUR_PROJECT_LOCATION';
// const apiEndpoint = 'YOUR_API_ENDPOINT';
// const timeout = <TIMEOUT_IN_MILLI_SECONDS>;

// Imports the Google Cloud Featurestore Service Client library
const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1;

// Specifies the location of the api endpoint
const clientOptions = {
apiEndpoint: apiEndpoint,
};

// Instantiates a client
const featurestoreServiceClient = new FeaturestoreServiceClient(
clientOptions
);

async function batchReadFeatureValues() {
// Configure the featurestoreId resource
const featurestore = `projects/${project}/locations/${location}/featurestores/${featurestoreId}`;
const csvReadInstances = {
gcsSource: {
uris: [inputCsvFile],
},
};

const destination = {
bigqueryDestination: {
// # Output to BigQuery table created earlier
outputUri: destinationTableUri,
},
};

const usersFeatureSelector = {
idMatcher: {
ids: [
// features, use "*" if you want to select all features within this entity type
'age',
'gender',
'liked_genres',
],
},
};

const usersEntityTypeSpec = {
// Read the 'age', 'gender' and 'liked_genres' features from the 'perm_users' entity
entityTypeId: 'perm_users',
featureSelector: usersFeatureSelector,
};

const moviesFeatureSelector = {
idMatcher: {
ids: ['*'],
},
};

const moviesEntityTypeSpec = {
// Read the all features from the 'perm_movies' entity
entityTypeId: 'perm_movies',
featureSelector: moviesFeatureSelector,
};

const entityTypeSpecs = [usersEntityTypeSpec, moviesEntityTypeSpec];

// Construct request
const request = {
featurestore: featurestore,
csvReadInstances: csvReadInstances,
destination: destination,
entityTypeSpecs: entityTypeSpecs,
};

// Batch Read Feature Values Request
const [operation] = await featurestoreServiceClient.batchReadFeatureValues(
request,
{timeout: Number(timeout)}
);
const [response] = await operation.promise();

console.log('Batch read feature values response');
console.log('Raw response:');
console.log(JSON.stringify(response, null, 2));
}
batchReadFeatureValues();
// [END aiplatform_batch_read_feature_values_sample]
}

process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});

main(...process.argv.slice(2));
Loading

0 comments on commit 4cef015

Please sign in to comment.