Skip to content

Commit 315e765

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
chore: Include type for vector_search_upsert_datapoints sample
PiperOrigin-RevId: 697694053
1 parent e56475c commit 315e765

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

samples/model-builder/test_constants.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,9 @@
380380

381381
# Vector Search
382382
VECTOR_SEARCH_INDEX = "123"
383-
VECTOR_SERACH_INDEX_DATAPOINTS = [
384-
{"datapoint_id": "datapoint_id_1", "feature_vector": [0.1]}
383+
VECTOR_SEARCH_INDEX_DATAPOINTS = [
384+
aiplatform.compat.types.index_v1beta1.IndexDatapoint(datapoint_id="datapoint_id_1", feature_vector=[0.1, 0.2]),
385+
aiplatform.compat.types.index_v1beta1.IndexDatapoint(datapoint_id="datapoint_id_2", feature_vector=[0.3, 0.4]),
385386
]
386387
VECTOR_SEARCH_INDEX_DATAPOINT_IDS = ["datapoint_id_1", "datapoint_id_2"]
387388
VECTOR_SEARCH_INDEX_ENDPOINT = "456"

samples/model-builder/vector_search/vector_search_stream_update_sample.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818

1919

2020
# [START aiplatform_sdk_vector_search_stream_update_sample]
21-
def stream_update_vector_search_index(
22-
project: str, location: str, index_name: str, datapoints: Sequence[dict]
21+
def vector_search_upsert_datapoints(
22+
project: str,
23+
location: str,
24+
index_name: str,
25+
datapoints: Sequence[aiplatform.compat.types.index_v1beta1.IndexDatapoint],
2326
) -> None:
24-
"""Stream update an existing vector search index
27+
"""Upsert datapoints to the index.
2528
2629
Args:
2730
project (str): Required. The Project ID
@@ -30,8 +33,10 @@ def stream_update_vector_search_index(
3033
resource name or a index ID. Example:
3134
"projects/123/locations/us-central1/indexes/my_index_id" or
3235
"my_index_id".
33-
datapoints: Sequence[dict]: Required. The datapoints to be updated. The dict
34-
element should be of the IndexDatapoint type.
36+
datapoints: Sequence[IndexDatapoint]: Required. The datapoints to be
37+
updated. For example:
38+
[IndexDatapoint(datapoint_id="1", feature_vector=[1.0, 2.0, 3.0]),
39+
IndexDatapoint(datapoint_id="2", feature_vector=[4.0, 5.0, 6.0])]
3540
"""
3641
# Initialize the Vertex AI client
3742
aiplatform.init(project=project, location=location)

samples/model-builder/vector_search/vector_search_stream_update_sample_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
def test_vector_search_stream_update_sample(
2020
mock_sdk_init, mock_index_init, mock_index_upsert_datapoints
2121
):
22-
vector_search_stream_update_sample.stream_update_vector_search_index(
22+
vector_search_stream_update_sample.vector_search_upsert_datapoints(
2323
project=constants.PROJECT,
2424
location=constants.LOCATION,
2525
index_name=constants.VECTOR_SEARCH_INDEX,
26-
datapoints=constants.VECTOR_SERACH_INDEX_DATAPOINTS,
26+
datapoints=constants.VECTOR_SEARCH_INDEX_DATAPOINTS,
2727
)
2828

2929
# Check client initialization
@@ -36,5 +36,5 @@ def test_vector_search_stream_update_sample(
3636

3737
# Check index.upsert_datapoints is called with right params.
3838
mock_index_upsert_datapoints.assert_called_with(
39-
datapoints=constants.VECTOR_SERACH_INDEX_DATAPOINTS
39+
datapoints=constants.VECTOR_SEARCH_INDEX_DATAPOINTS
4040
)

0 commit comments

Comments
 (0)