-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add more vector search samples
PiperOrigin-RevId: 688286858
- Loading branch information
1 parent
3a4ebf5
commit af50cd4
Showing
21 changed files
with
953 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
samples/model-builder/vector_search/vector_search_delete_index_endpoint_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright 2024 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. | ||
|
||
from google.cloud import aiplatform | ||
|
||
|
||
# [START aiplatform_sdk_vector_search_delete_index_endpoint_sample] | ||
def vector_search_delete_index_endpoint( | ||
project: str, location: str, index_endpoint_name: str, force: bool = False | ||
) -> None: | ||
"""Delete a vector search index endpoint. | ||
Args: | ||
project (str): Required. Project ID | ||
location (str): Required. The region name | ||
index_endpoint_name (str): Required. Index endpoint to run the query | ||
against. | ||
force (bool): Required. If true, undeploy any deployed indexes on this | ||
endpoint before deletion. | ||
""" | ||
# Initialize the Vertex AI client | ||
aiplatform.init(project=project, location=location) | ||
|
||
# Create the index endpoint instance from an existing endpoint | ||
index_endpoint = aiplatform.MatchingEngineIndexEndpoint( | ||
index_endpoint_name=index_endpoint_name | ||
) | ||
|
||
# Delete the index endpoint | ||
index_endpoint.delete(force=force) | ||
|
||
|
||
# [END aiplatform_sdk_vector_search_delete_index_endpoint_sample] |
43 changes: 43 additions & 0 deletions
43
samples/model-builder/vector_search/vector_search_delete_index_endpoint_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2024 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. | ||
|
||
import test_constants as constants | ||
from vector_search import vector_search_delete_index_endpoint_sample | ||
|
||
|
||
def test_vector_search_delete_index_endpoint_sample( | ||
mock_sdk_init, | ||
mock_index_endpoint_init, | ||
mock_index_endpoint_delete, | ||
): | ||
vector_search_delete_index_endpoint_sample.vector_search_delete_index_endpoint( | ||
project=constants.PROJECT, | ||
location=constants.LOCATION, | ||
index_endpoint_name=constants.VECTOR_SEARCH_INDEX_ENDPOINT, | ||
force=True, | ||
) | ||
|
||
# Check client initialization | ||
mock_sdk_init.assert_called_with( | ||
project=constants.PROJECT, | ||
location=constants.LOCATION, | ||
) | ||
|
||
# Check index endpoint initialization with right index endpoint name | ||
mock_index_endpoint_init.assert_called_with( | ||
index_endpoint_name=constants.VECTOR_SEARCH_INDEX_ENDPOINT | ||
) | ||
|
||
# Check index deletion | ||
mock_index_endpoint_delete.assert_called_with(force=True) |
42 changes: 42 additions & 0 deletions
42
samples/model-builder/vector_search/vector_search_delete_index_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright 2024 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. | ||
|
||
from google.cloud import aiplatform | ||
|
||
|
||
# [START aiplatform_sdk_vector_search_delete_index_sample] | ||
def vector_search_delete_index( | ||
project: str, location: str, index_name: str | ||
) -> None: | ||
"""Delete a vector search index. | ||
Args: | ||
project (str): Required. Project ID | ||
location (str): Required. The region name | ||
index_name (str): Required. The index to update. A fully-qualified index | ||
resource name or a index ID. Example: | ||
"projects/123/locations/us-central1/indexes/my_index_id" or | ||
"my_index_id". | ||
""" | ||
# Initialize the Vertex AI client | ||
aiplatform.init(project=project, location=location) | ||
|
||
# Create the index instance from an existing index | ||
index = aiplatform.MatchingEngineIndex(index_name=index_name) | ||
|
||
# Delete the index | ||
index.delete() | ||
|
||
|
||
# [END aiplatform_sdk_vector_search_delete_index_sample] |
40 changes: 40 additions & 0 deletions
40
samples/model-builder/vector_search/vector_search_delete_index_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright 2024 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. | ||
|
||
import test_constants as constants | ||
from vector_search import vector_search_delete_index_sample | ||
|
||
|
||
def test_vector_search_delete_index_sample( | ||
mock_sdk_init, | ||
mock_index_init, | ||
mock_index_delete, | ||
): | ||
vector_search_delete_index_sample.vector_search_delete_index( | ||
project=constants.PROJECT, | ||
location=constants.LOCATION, | ||
index_name=constants.VECTOR_SEARCH_INDEX, | ||
) | ||
|
||
# Check client initialization | ||
mock_sdk_init.assert_called_with( | ||
project=constants.PROJECT, | ||
location=constants.LOCATION, | ||
) | ||
|
||
# Check index initialization with right index name | ||
mock_index_init.assert_called_with(index_name=constants.VECTOR_SEARCH_INDEX) | ||
|
||
# Check index deletion | ||
mock_index_delete.assert_called() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.