mirror of
https://github.com/GoogleCloudPlatform/vertex-ai-samples.git
synced 2026-09-26 14:42:04 +00:00
Update FS optimized serving GA colab (#2859)
* Update FS optimized serving GA colab * Fix import order * Fix import format * Fix format * Fix test issue * Fix format * Add way to getFOS&FV for FR/FG
This commit is contained in:
+117
-160
@@ -269,7 +269,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"REGION = \"us-central1\" # @param {type: \"string\"}"
|
||||
"REGION = \"us-east1\" # @param {type: \"string\"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -363,8 +363,7 @@
|
||||
"source": [
|
||||
"from google.cloud import aiplatform, bigquery\n",
|
||||
"from google.cloud.aiplatform_v1beta1 import (\n",
|
||||
" FeatureOnlineStoreAdminServiceClient, FeatureOnlineStoreServiceClient,\n",
|
||||
" FeatureRegistryServiceClient)\n",
|
||||
" FeatureOnlineStoreAdminServiceClient, FeatureRegistryServiceClient)\n",
|
||||
"from google.cloud.aiplatform_v1beta1.types import feature as feature_pb2\n",
|
||||
"from google.cloud.aiplatform_v1beta1.types import \\\n",
|
||||
" feature_group as feature_group_pb2\n",
|
||||
@@ -374,8 +373,6 @@
|
||||
" feature_online_store_admin_service as \\\n",
|
||||
" feature_online_store_admin_service_pb2\n",
|
||||
"from google.cloud.aiplatform_v1beta1.types import \\\n",
|
||||
" feature_online_store_service as feature_online_store_service_pb2\n",
|
||||
"from google.cloud.aiplatform_v1beta1.types import \\\n",
|
||||
" feature_registry_service as feature_registry_service_pb2\n",
|
||||
"from google.cloud.aiplatform_v1beta1.types import \\\n",
|
||||
" feature_view as feature_view_pb2\n",
|
||||
@@ -383,7 +380,8 @@
|
||||
" featurestore_service as featurestore_service_pb2\n",
|
||||
"from google.cloud.aiplatform_v1beta1.types import io as io_pb2\n",
|
||||
"from google.cloud.aiplatform_v1beta1.types import \\\n",
|
||||
" service_networking as service_networking_pb2"
|
||||
" service_networking as service_networking_pb2\n",
|
||||
"from vertexai.resources.preview import FeatureOnlineStore, FeatureView"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -664,6 +662,29 @@
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "34yy_HOfR3Ia"
|
||||
},
|
||||
"source": [
|
||||
"#### Use SDK to get FeatureOnlineStore"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "MutKQwGlR43o"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fos_list = FeatureOnlineStore.list()\n",
|
||||
"for fos in fos_list:\n",
|
||||
" if fos.name == FEATURE_ONLINE_STORE_ID:\n",
|
||||
" my_fos = fos"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
@@ -687,22 +708,12 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Create FeatureOnlineStore with public endpoint\n",
|
||||
"FEATURE_ONLINE_STORE_ID = (\n",
|
||||
" \"the_look_demo_optimized_public_unique\" # @param {type:\"string\"}\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"online_store_config = feature_online_store_pb2.FeatureOnlineStore(\n",
|
||||
" optimized=feature_online_store_pb2.FeatureOnlineStore.Optimized()\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"create_store_lro = admin_client.create_feature_online_store(\n",
|
||||
" feature_online_store_admin_service_pb2.CreateFeatureOnlineStoreRequest(\n",
|
||||
" parent=f\"projects/{PROJECT_ID}/locations/{REGION}\",\n",
|
||||
" feature_online_store_id=FEATURE_ONLINE_STORE_ID,\n",
|
||||
" feature_online_store=online_store_config,\n",
|
||||
" )\n",
|
||||
")"
|
||||
"my_fos = FeatureOnlineStore.create_optimized_store(FEATURE_ONLINE_STORE_ID)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -715,28 +726,7 @@
|
||||
"\n",
|
||||
"After the long-running operation (LRO) is complete, show the result.\n",
|
||||
"\n",
|
||||
"> **Note:** This operation might take up to 10 minutes to complete."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "zDDZdSVzrV5Q"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Wait for the LRO to finish and get the LRO result.\n",
|
||||
"print(create_store_lro.result())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "wlJ7gMSAH8lm"
|
||||
},
|
||||
"source": [
|
||||
"Verify that the `FeatureOnlineStore` instance is created by listing all online stores for the location."
|
||||
"> **Note:** This operation might take up to 10 minutes to complete for the first FeatureOnlineStore creation in the region of new project."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -747,10 +737,8 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Use list to verify the store is created.\n",
|
||||
"admin_client.list_feature_online_stores(\n",
|
||||
" parent=f\"projects/{PROJECT_ID}/locations/{REGION}\"\n",
|
||||
")"
|
||||
"# Wait for the LRO to finish and get the FeatureOnlineStore info\n",
|
||||
"my_fos.gca_resource"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -808,29 +796,43 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Create FeatureView\n",
|
||||
"FEATURE_VIEW_ID = \"product\" # @param {type:\"string\"}\n",
|
||||
"CRON_SCHEDULE = \"TZ=America/Los_Angeles 56 * * * *\" # @param {type:\"string\"}\n",
|
||||
"\n",
|
||||
"big_query_source = feature_view_pb2.FeatureView.BigQuerySource(\n",
|
||||
" uri=f\"bq://{BQ_VIEW_ID_FQN}\", entity_id_columns=[\"entity_id\"]\n",
|
||||
")\n",
|
||||
"# CRON_SCHEDULE = \"TZ=America/Los_Angeles 56 * * * *\" # @param {type:\"string\"}\n",
|
||||
"\n",
|
||||
"sync_config = feature_view_pb2.FeatureView.SyncConfig(cron=CRON_SCHEDULE)\n",
|
||||
"my_fv = my_fos.create_feature_view_from_big_query(\n",
|
||||
" FEATURE_VIEW_ID,\n",
|
||||
" FeatureView.BigQuerySource(\n",
|
||||
" uri=f\"bq://{BQ_VIEW_ID_FQN}\",\n",
|
||||
" entity_id_columns=[\"entity_id\"],\n",
|
||||
" ),\n",
|
||||
" # sync_config can be set with CRON_SCHEDULE if you want to setup auto sync\n",
|
||||
" sync_config=None,\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "l1CnCKzCSTXd"
|
||||
},
|
||||
"source": [
|
||||
"#### Verify FeatureView instance creation\n",
|
||||
"\n",
|
||||
"create_view_lro = admin_client.create_feature_view(\n",
|
||||
" feature_online_store_admin_service_pb2.CreateFeatureViewRequest(\n",
|
||||
" parent=f\"projects/{PROJECT_ID}/locations/{REGION}/featureOnlineStores/{FEATURE_ONLINE_STORE_ID}\",\n",
|
||||
" feature_view_id=FEATURE_VIEW_ID,\n",
|
||||
" feature_view=feature_view_pb2.FeatureView(\n",
|
||||
" big_query_source=big_query_source,\n",
|
||||
" sync_config=sync_config,\n",
|
||||
" ),\n",
|
||||
" )\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Wait for LRO to complete and show result\n",
|
||||
"print(create_view_lro.result())"
|
||||
"After the long-running operation (LRO) is complete, show the result."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "BCIt_EMMSUe_"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Wait for the LRO to finish and get the FeatureView info\n",
|
||||
"my_fv.gca_resource"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1041,6 +1043,36 @@
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "m8YTzBUEBL_F"
|
||||
},
|
||||
"source": [
|
||||
"#### Use SDK to get FeatureOnlineStore and FeatureView"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "B4vMrmItBM_B"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Uncomment if you use FeatureGroups/Features\n",
|
||||
"# fos_list = FeatureOnlineStore.list()\n",
|
||||
"# for fos in fos_list:\n",
|
||||
"# if fos.name == FEATURE_ONLINE_STORE_ID:\n",
|
||||
"# my_fos = fos\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# fv_list = FeatureView.list(feature_online_store_id=FEATURE_ONLINE_STORE_ID)\n",
|
||||
"# for fv in fv_list:\n",
|
||||
"# if fv.name == FEATURE_VIEW_ID:\n",
|
||||
"# my_fv = fv"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
@@ -1062,9 +1094,8 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"sync_response = admin_client.sync_feature_view(\n",
|
||||
" feature_view=f\"projects/{PROJECT_ID}/locations/{REGION}/featureOnlineStores/{FEATURE_ONLINE_STORE_ID}/featureViews/{FEATURE_VIEW_ID}\"\n",
|
||||
")"
|
||||
"# Sync the FeatureView\n",
|
||||
"fv_sync = my_fv.sync()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1089,40 +1120,18 @@
|
||||
"import time\n",
|
||||
"\n",
|
||||
"while True:\n",
|
||||
" feature_view_sync = admin_client.get_feature_view_sync(\n",
|
||||
" name=sync_response.feature_view_sync\n",
|
||||
" )\n",
|
||||
" feature_view_sync = my_fv.get_sync(fv_sync.resource_name.split(\"/\")[9]).gca_resource\n",
|
||||
" if feature_view_sync.run_time.end_time.seconds > 0:\n",
|
||||
" status = \"Succeed\" if feature_view_sync.final_status.code == 0 else \"Failed\"\n",
|
||||
" print(f\"Sync {status} for {feature_view_sync.name}.\")\n",
|
||||
" # wait a little more for the job to properly shutdown\n",
|
||||
" time.sleep(30)\n",
|
||||
" break\n",
|
||||
" else:\n",
|
||||
" print(\"Sync ongoing, waiting for 30 seconds.\")\n",
|
||||
" time.sleep(30)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "KUKDx4a72a_M"
|
||||
},
|
||||
"source": [
|
||||
"Use `list_feature_view_syncs` to view all your syncs."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "NCwJFqYB2X5n"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"admin_client.list_feature_view_syncs(\n",
|
||||
" parent=f\"projects/{PROJECT_ID}/locations/{REGION}/featureOnlineStores/{FEATURE_ONLINE_STORE_ID}/featureViews/{FEATURE_VIEW_ID}\"\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
@@ -1244,6 +1253,7 @@
|
||||
"# Uncomment the following code blocks after your PSC setup is complete. Replace {endpoint_ip} with the IP of the new connection.\n",
|
||||
"\n",
|
||||
"# from google.cloud.aiplatform_v1beta1.services.feature_online_store_service.transports.grpc import FeatureOnlineStoreServiceGrpcTransport\n",
|
||||
"# from google.cloud.aiplatform_v1beta1 import FeatureOnlineStoreServiceClient\n",
|
||||
"# import grpc\n",
|
||||
"\n",
|
||||
"# data_client = FeatureOnlineStoreServiceClient(\n",
|
||||
@@ -1273,6 +1283,8 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# from google.cloud.aiplatform_v1beta1.types import \\\n",
|
||||
"# feature_online_store_service as feature_online_store_service_pb2\n",
|
||||
"# data_client.fetch_feature_values(\n",
|
||||
"# request=feature_online_store_service_pb2.FetchFeatureValuesRequest(\n",
|
||||
"# feature_view=f\"projects/{PROJECT_ID}/locations/{REGION}/featureOnlineStores/{FEATURE_ONLINE_STORE_ID}/featureViews/{FEATURE_VIEW_ID}\",\n",
|
||||
@@ -1301,61 +1313,6 @@
|
||||
"Retrieve the information to connect to your `FeatureOnlineStore` instance."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "48rVCKQX5-lA"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Get Optimized online store\n",
|
||||
"response = admin_client.get_feature_online_store(\n",
|
||||
" name=f\"projects/{PROJECT_ID}/locations/{REGION}/featureOnlineStores/{FEATURE_ONLINE_STORE_ID}\"\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "uOed1KFe6JoT"
|
||||
},
|
||||
"source": [
|
||||
"You'll see output similar to the following:\n",
|
||||
"\n",
|
||||
"```\n",
|
||||
"dedicatedServingEndpoint {\n",
|
||||
" publicEndpointDomainName: \"public_endpoint_domain_name_string\"\n",
|
||||
"}\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"* `public_endpoint_domain_name_string` represents the target service domain name"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "c3pJS3AZbIsQ"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"data_client = FeatureOnlineStoreServiceClient(\n",
|
||||
" client_options={\n",
|
||||
" \"api_endpoint\": response.dedicated_serving_endpoint.public_endpoint_domain_name\n",
|
||||
" }\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "o6TMOrx7bQNO"
|
||||
},
|
||||
"source": [
|
||||
"You can specify the response format using `FetchFeatureValuesRequest.Format`. If you don't specify a format, then the format is set to `KEY_VALUE`, by default. `PROTO_STRUCT` is another supported format."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -1364,13 +1321,18 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"data_client.fetch_feature_values(\n",
|
||||
" request=feature_online_store_service_pb2.FetchFeatureValuesRequest(\n",
|
||||
" feature_view=f\"projects/{PROJECT_ID}/locations/{REGION}/featureOnlineStores/{FEATURE_ONLINE_STORE_ID}/featureViews/{FEATURE_VIEW_ID}\",\n",
|
||||
" id=\"16050\",\n",
|
||||
" format=feature_online_store_service_pb2.FetchFeatureValuesRequest.Format.PROTO_STRUCT,\n",
|
||||
" )\n",
|
||||
")"
|
||||
"# It will take some time for the DNS to be fully ready\n",
|
||||
"time.sleep(200)\n",
|
||||
"\n",
|
||||
"# Depends on the FeatureView you created, the FEATURE_VIEW_ID here can be different\n",
|
||||
"FEATURE_VIEW_ID = \"product\" # @param {type:\"string\"}\n",
|
||||
"data = (\n",
|
||||
" FeatureView(name=FEATURE_VIEW_ID, feature_online_store_id=FEATURE_ONLINE_STORE_ID)\n",
|
||||
" .read(key=[\"13842\"])\n",
|
||||
" .to_dict()\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"print(data)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1407,15 +1369,10 @@
|
||||
")\n",
|
||||
"\n",
|
||||
"# Delete FeatureViews\n",
|
||||
"admin_client.delete_feature_view(\n",
|
||||
" name=f\"projects/{PROJECT_ID}/locations/{REGION}/featureOnlineStores/{FEATURE_ONLINE_STORE_ID}/featureViews/{FEATURE_VIEW_ID}\"\n",
|
||||
")\n",
|
||||
"my_fv.delete\n",
|
||||
"\n",
|
||||
"# Delete OnlineStore\n",
|
||||
"admin_client.delete_feature_online_store(\n",
|
||||
" name=f\"projects/{PROJECT_ID}/locations/{REGION}/featureOnlineStores/{FEATURE_ONLINE_STORE_ID}\",\n",
|
||||
" force=True,\n",
|
||||
")\n",
|
||||
"my_fos.delete(force=True)\n",
|
||||
"\n",
|
||||
"# Delete BigQuery dataset. Uncomment and run the command below if you want to delete the BigQuery set.\n",
|
||||
"# Do this only if the dataset is created for this demo.\n",
|
||||
|
||||
Reference in New Issue
Block a user