Compare commits

...
Author SHA1 Message Date
Andrew Ferlitsch 210d830da3 fix: lint 2023-10-27 21:29:37 +00:00
Andrew Ferlitsch 68ea7bb113 fix: add VPC network 2023-10-26 23:16:31 +00:00
Andrew Ferlitsch 70b1a75b25 fix: handle exception 2023-10-25 21:27:11 +00:00
Andrew Ferlitsch fd5114e963 fix: VPC issue 2023-10-25 18:18:37 +00:00
Andrew Ferlitsch 56fb42a68f fix: VPC issue 2023-10-25 18:16:09 +00:00
Andrew Ferlitsch 5ef1f96d83 fix: learn more about 2023-10-24 19:57:09 +00:00
@@ -62,7 +62,7 @@
"\n",
"This example demonstrates how to create text-to-image embeddings using the DiffusionDB dataset and the Vertex AI Multimodal Embeddings model. The embeddings are uploaded to the Vertex AI Vector Search service, which is a high scale, low latency solution to find similar vectors for a large corpus. Moreover, it is a fully managed offering, further reducing operational overhead. It is built upon [Approximate Nearest Neighbor (ANN) technology](https://ai.googleblog.com/2020/07/announcing-scann-efficient-vector.html) developed by Google Research.\n",
"\n",
"To learn more, see the official documentation for [Vertex AI Multimodal Embeddings](https://cloud.google.com/vertex-ai/docs/generative-ai/embeddings/get-multimodal-embeddings#supported_models), and [Vertex AI Vector Search](https://cloud.google.com/vertex-ai/docs/matching-engine/overview)."
"To learn more about [Vertex AI Multimodal Embeddings](https://cloud.google.com/vertex-ai/docs/generative-ai/embeddings/get-multimodal-embeddings#supported_models), and [Vertex AI Vector Search](https://cloud.google.com/vertex-ai/docs/matching-engine/overview)."
]
},
{
@@ -968,11 +968,14 @@
"# Calculate text embedding of query\n",
"text_embedding = encode_texts_to_embeddings(text=[text_query])[0]\n",
"\n",
"print(type(text_embedding))\n",
"print(type(text_embedding[0]))\n",
"try:\n",
" print(type(text_embedding))\n",
" print(type(text_embedding[0]))\n",
"\n",
"print(type(image_embeddings))\n",
"print(type(image_embeddings[0]))\n",
" print(type(image_embeddings))\n",
" print(type(image_embeddings[0]))\n",
"except Exception as e:\n",
" print(e)\n",
"\n",
"# Calculate distance\n",
"distances = dot_product_distance(\n",
@@ -1012,7 +1015,7 @@
" axs[row_idx, col_idx].imshow(image, cmap=\"gray\")\n",
"\n",
" # Set the title of the subplot to the image index and score\n",
" axs[row_idx, col_idx].set_title(f\"Rank {i+1}, Distance = {distance:.2f}\")\n",
" axs[row_idx, col_idx].set_title(f\"Rank {i+1}, Distance = {distance:.2f}\") # noqa\n",
"\n",
" # Remove ticks from the subplot\n",
" axs[row_idx, col_idx].set_xticks([])\n",
@@ -1228,6 +1231,32 @@
"tree_ah_index = aiplatform.MatchingEngineIndex(index_name=INDEX_RESOURCE_NAME)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "qV2xjAnDDObD"
},
"source": [
"## Create an IndexEndpoint with VPC Network"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "BpZQoJyxDlbO"
},
"outputs": [],
"source": [
"# Retrieve the project number\n",
"PROJECT_NUMBER = !gcloud projects list --filter=\"PROJECT_ID:'{PROJECT_ID}'\" --format='value(PROJECT_NUMBER)'\n",
"PROJECT_NUMBER = PROJECT_NUMBER[0]\n",
"\n",
"VPC_NETWORK = \"[your-network-name]\"\n",
"VPC_NETWORK_FULL = \"projects/{}/global/networks/{}\".format(PROJECT_NUMBER, VPC_NETWORK)\n",
"VPC_NETWORK_FULL"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -1248,7 +1277,8 @@
"my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint.create(\n",
" display_name=DISPLAY_NAME,\n",
" description=DISPLAY_NAME,\n",
" public_endpoint_enabled=True,\n",
" public_endpoint_enabled=False,\n",
" network=VPC_NETWORK_FULL,\n",
")"
]
},
@@ -1321,7 +1351,7 @@
"# Define number of neighbors to return\n",
"NUM_NEIGHBORS = 20\n",
"\n",
"response = my_index_endpoint.find_neighbors(\n",
"response = my_index_endpoint.match(\n",
" deployed_index_id=DEPLOYED_INDEX_ID,\n",
" queries=text_embeddings,\n",
" num_neighbors=NUM_NEIGHBORS,\n",
@@ -1368,7 +1398,7 @@
" axs[row_idx, col_idx].imshow(image, cmap=\"gray\")\n",
"\n",
" # Set the title of the subplot to the image index and score\n",
" axs[row_idx, col_idx].set_title(f\"Rank {i+1}, Score = {score:.2f}\")\n",
" axs[row_idx, col_idx].set_title(f\"Rank {i+1}, Score = {score:.2f}\") # noqa\n",
"\n",
" # Remove ticks from the subplot\n",
" axs[row_idx, col_idx].set_xticks([])\n",