Skip to content

Commit 2fbf5a5

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: sample code for Vertex AI Feature Store
PiperOrigin-RevId: 645230368
1 parent f6b6dee commit 2fbf5a5

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

samples/model-builder/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,21 @@ 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_feature_group():
721+
mock = MagicMock(preview_resources.FeatureGroup)
722+
yield mock
723+
724+
725+
@pytest.fixture
726+
def mock_create_feature_group(mock_feature_group):
727+
with patch.object(
728+
preview_resources.FeatureGroup, "create"
729+
) as mock_create_feature_group:
730+
mock_create_feature_group.return_value = mock_feature_group
731+
yield mock_create_feature_group
732+
733+
719734
@pytest.fixture
720735
def mock_create_optimized_private_online_store(mock_feature_online_store):
721736
with patch.object(
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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_feature_group_sample]
16+
17+
from google.cloud import aiplatform
18+
from vertexai.resources.preview import feature_store
19+
20+
21+
def create_feature_group_sample(
22+
project: str,
23+
location: str,
24+
feature_group_id: str,
25+
):
26+
aiplatform.init(project=project, location=location)
27+
fg = feature_store.FeatureGroup.create(
28+
feature_group_id
29+
)
30+
return fg
31+
32+
33+
# [END aiplatform_sdk_create_feature_group_sample]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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_feature_group_sample
16+
17+
import test_constants as constants
18+
19+
20+
def test_create_feature_group_sample(
21+
mock_sdk_init, mock_create_feature_group
22+
):
23+
create_feature_group_sample.create_feature_group_sample(
24+
project=constants.PROJECT,
25+
location=constants.LOCATION,
26+
feature_group_id=constants.FEATURE_GROUP_ID,
27+
)
28+
29+
mock_sdk_init.assert_called_once_with(
30+
project=constants.PROJECT, location=constants.LOCATION
31+
)
32+
33+
mock_create_feature_group.assert_called_once_with(
34+
constants.FEATURE_GROUP_ID
35+
)

samples/model-builder/test_constants.py

Lines changed: 1 addition & 0 deletions
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+
FEATURE_GROUP_ID = "sample_feature_group"
257258
PROJECT_ALLOWLISTED = ["test-project"]
258259

259260
TABULAR_TARGET_COLUMN = "target_column"

0 commit comments

Comments
 (0)