Skip to content

Commit e352175

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Add sample code show how to create an optimized private online store in Vertex AI Feature Store.
PiperOrigin-RevId: 644127795
1 parent 831c8e4 commit e352175

4 files changed

+86
-0
lines changed

samples/model-builder/conftest.py

+9
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,15 @@ def mock_create_optimized_public_online_store(mock_feature_online_store):
716716
yield mock_create_optimized_store
717717

718718

719+
@pytest.fixture
720+
def mock_create_optimized_private_online_store(mock_feature_online_store):
721+
with patch.object(
722+
preview_resources.FeatureOnlineStore, "create_optimized_store"
723+
) as mock_create_optimized_store:
724+
mock_create_optimized_store.return_value = mock_feature_online_store
725+
yield mock_create_optimized_store
726+
727+
719728
"""
720729
----------------------------------------------------------------------------
721730
Experiment Tracking Fixtures
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START aiplatform_sdk_create_optimized_private_feature_online_store_sample]
16+
17+
from typing import List
18+
19+
from google.cloud import aiplatform
20+
from vertexai.resources.preview import feature_store
21+
22+
23+
def create_optimized_private_feature_online_store_sample(
24+
project: str,
25+
location: str,
26+
feature_online_store_id: str,
27+
project_allowlist: List[str],
28+
):
29+
aiplatform.init(project=project, location=location)
30+
fos = feature_store.FeatureOnlineStore.create_optimized_store(
31+
name=feature_online_store_id,
32+
enable_private_service_connect=True,
33+
project_allowlist=project_allowlist,
34+
)
35+
return fos
36+
37+
38+
# [END aiplatform_sdk_create_optimized_private_feature_online_store_sample]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from feature_store import create_optimized_private_feature_online_store_sample
16+
import test_constants as constants
17+
18+
19+
def test_create_optimized_feature_online_store_sample(
20+
mock_sdk_init, mock_create_optimized_private_online_store
21+
):
22+
23+
create_optimized_private_feature_online_store_sample.create_optimized_private_feature_online_store_sample(
24+
project=constants.PROJECT,
25+
location=constants.LOCATION,
26+
feature_online_store_id=constants.FEATURE_ONLINE_STORE_ID,
27+
project_allowlist=constants.PROJECT_ALLOWLISTED,
28+
)
29+
30+
mock_sdk_init.assert_called_once_with(
31+
project=constants.PROJECT, location=constants.LOCATION
32+
)
33+
34+
mock_create_optimized_private_online_store.assert_called_once_with(
35+
name=constants.FEATURE_ONLINE_STORE_ID,
36+
enable_private_service_connect=True,
37+
project_allowlist=constants.PROJECT_ALLOWLISTED,
38+
)

samples/model-builder/test_constants.py

+1
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@
254254

255255
# Feature online store constants
256256
FEATURE_ONLINE_STORE_ID = "sample_feature_online_store"
257+
PROJECT_ALLOWLISTED = ["test-project"]
257258

258259
TABULAR_TARGET_COLUMN = "target_column"
259260
FORECASTNG_TIME_COLUMN = "date"

0 commit comments

Comments
 (0)