Addressed TW comments

This commit is contained in:
ivanmkc@google.com
2023-03-07 12:07:46 -05:00
parent 6a2d06f8f4
commit 080d1819ed
@@ -3,7 +3,6 @@
{
"cell_type": "code",
"execution_count": 1,
"id": "964a8f02",
"metadata": {
"id": "ur8xi4C7S06n"
},
@@ -26,7 +25,6 @@
},
{
"cell_type": "markdown",
"id": "c6e85f4a",
"metadata": {
"id": "JAPoU8Sm5E6e"
},
@@ -56,14 +54,13 @@
},
{
"cell_type": "markdown",
"id": "04199257",
"metadata": {
"id": "b0a74aaf1481"
},
"source": [
"## Overview\n",
"\n",
"This example demonstrates how to create text-to-image embeddings using the DiffusionDB dataset and the CLIP model. These are uploaded to Vertex AI Matching Engine service. It 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",
"This example demonstrates how to create text-to-image embeddings using the DiffusionDB dataset and the CLIP model. These are uploaded to the Vertex AI Matching Engine service. It 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",
"**Pre-requisite**: This notebook requires you to already have a VPC network set up. See the \"Prepare a VPC network\" section in [Create Vertex AI Matching Engine index notebook](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/sdk_matching_engine_for_indexing.ipynb).\n",
"\n",
@@ -72,14 +69,13 @@
},
{
"cell_type": "markdown",
"id": "8f5c8219",
"metadata": {
"id": "34a4b245e795"
},
"source": [
"### Objective\n",
"\n",
"In this notebook, you learn how to encode custom text embeddings, create an Approximate Nearest Neighbor (ANN) Index, and query against indexes.\n",
"In this notebook, you learn how to encode custom text embeddings, create an Approximate Nearest Neighbor (ANN) index, and query against indexes.\n",
"\n",
"This tutorial uses the following Google Cloud ML services:\n",
"\n",
@@ -87,15 +83,14 @@
"\n",
"The steps performed include:\n",
"\n",
"* Create ANN Index\n",
"* Create an IndexEndpoint with VPC Network\n",
"* Deploy ANN Index\n",
"* Create ANN index\n",
"* Create an index endpoint with VPC Network\n",
"* Deploy ANN index\n",
"* Perform online query\n"
]
},
{
"cell_type": "markdown",
"id": "3a748268",
"metadata": {
"id": "tvgnzT1CKxrO"
},
@@ -109,20 +104,18 @@
},
{
"cell_type": "markdown",
"id": "057c74e0",
"metadata": {
"id": "f0f1bea346db"
},
"source": [
"## Installation\n",
"\n",
"Install the latest version of Cloud Storage, BigQuery and Vertex AI SDKs for Python."
"Install the latest version of Cloud Storage, BigQuery and the Vertex AI SDK for Python."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97ab337f",
"metadata": {
"id": "dfbccc635a17"
},
@@ -135,18 +128,16 @@
},
{
"cell_type": "markdown",
"id": "4d66b632",
"metadata": {
"id": "2209c11552af"
},
"source": [
"Install the latest version of transformers and torch libraries for encoding text and image embeddings."
"Install the latest version of transformers and torch libraries for encoding text and image embeddings"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7659ca92",
"metadata": {
"id": "f455fbba6a33"
},
@@ -158,7 +149,6 @@
},
{
"cell_type": "markdown",
"id": "0bc05e6e",
"metadata": {
"id": "5b08ba354c6e"
},
@@ -169,7 +159,6 @@
{
"cell_type": "code",
"execution_count": 4,
"id": "27c83e0f",
"metadata": {
"id": "bea801acf6b5"
},
@@ -184,7 +173,6 @@
},
{
"cell_type": "markdown",
"id": "c4b07d27",
"metadata": {
"id": "dd28c9e4f067"
},
@@ -192,7 +180,7 @@
"## Before you begin\n",
"#### Set your project ID\n",
"\n",
"**If you don't know your project ID**, try the following:\n",
"If you don't know your project ID, try the following:\n",
"* Run `gcloud config list`.\n",
"* Run `gcloud projects list`.\n",
"* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)"
@@ -201,7 +189,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "e3ab460b",
"metadata": {
"id": "80c0215f05a0"
},
@@ -215,7 +202,6 @@
},
{
"cell_type": "markdown",
"id": "54ff4cee",
"metadata": {
"id": "4f4512bf63b3"
},
@@ -228,7 +214,6 @@
{
"cell_type": "code",
"execution_count": 6,
"id": "bbbab50b",
"metadata": {
"id": "474be5183c27"
},
@@ -239,7 +224,6 @@
},
{
"cell_type": "markdown",
"id": "488dcd36",
"metadata": {
"id": "949271bfebe3"
},
@@ -251,7 +235,6 @@
},
{
"cell_type": "markdown",
"id": "9c66af92",
"metadata": {
"id": "b65b4ce80d9a"
},
@@ -262,7 +245,6 @@
},
{
"cell_type": "markdown",
"id": "1b385497",
"metadata": {
"id": "985cdbfe7372"
},
@@ -273,7 +255,6 @@
{
"cell_type": "code",
"execution_count": 7,
"id": "e5f19f14",
"metadata": {
"id": "fbc9cd30cc4b"
},
@@ -284,7 +265,6 @@
},
{
"cell_type": "markdown",
"id": "df1d8c35",
"metadata": {
"id": "79efab26ad02"
},
@@ -295,7 +275,6 @@
{
"cell_type": "code",
"execution_count": 8,
"id": "1478d7b6",
"metadata": {
"id": "a336a05c6149"
},
@@ -307,7 +286,6 @@
},
{
"cell_type": "markdown",
"id": "4034fe2e",
"metadata": {
"id": "0c0a44fa330f"
},
@@ -318,7 +296,6 @@
},
{
"cell_type": "markdown",
"id": "64f472dc",
"metadata": {
"id": "d3uj8x73nDX_"
},
@@ -328,7 +305,6 @@
},
{
"cell_type": "markdown",
"id": "86cce2ad",
"metadata": {
"id": "hhq5zEbGg0XX"
},
@@ -339,7 +315,6 @@
{
"cell_type": "code",
"execution_count": 9,
"id": "ac1c1066",
"metadata": {
"id": "EzrelQZ22IZj"
},
@@ -354,7 +329,6 @@
},
{
"cell_type": "markdown",
"id": "5b7c9fb9",
"metadata": {
"id": "zgPO1eR3CYjk"
},
@@ -367,7 +341,6 @@
{
"cell_type": "code",
"execution_count": 10,
"id": "62083738",
"metadata": {
"id": "MzGDU7TWdts_"
},
@@ -378,7 +351,6 @@
},
{
"cell_type": "markdown",
"id": "ab8b1acc",
"metadata": {
"id": "-EcIXiGsCePi"
},
@@ -389,7 +361,6 @@
{
"cell_type": "code",
"execution_count": 11,
"id": "6fb2bb55",
"metadata": {
"id": "NIq7R4HZCfIc"
},
@@ -398,7 +369,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Creating gs://your-bucket-name-ah1mxx7t/...\r\n"
"Creating gs://your-bucket-name-ah1mxx7t/...\n"
]
}
],
@@ -408,7 +379,6 @@
},
{
"cell_type": "markdown",
"id": "8fbd956f",
"metadata": {
"id": "lR6Wwv-hCCN-"
},
@@ -420,7 +390,6 @@
},
{
"cell_type": "markdown",
"id": "31ad8169",
"metadata": {
"id": "9e2a05095082"
},
@@ -431,7 +400,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "71f7463f",
"metadata": {
"id": "9wzS85TeB9dG"
},
@@ -442,7 +410,6 @@
},
{
"cell_type": "markdown",
"id": "c648e76d",
"metadata": {
"id": "49ee8d2c2df7"
},
@@ -453,7 +420,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "49a81f2b",
"metadata": {
"id": "ed67efa3c0f3"
},
@@ -464,7 +430,6 @@
},
{
"cell_type": "markdown",
"id": "e63c3592",
"metadata": {
"id": "d0bc039db70e"
},
@@ -475,7 +440,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "1f529fa4",
"metadata": {
"id": "7d27d986c61f"
},
@@ -487,7 +451,6 @@
},
{
"cell_type": "markdown",
"id": "e33f17d2",
"metadata": {
"id": "a514786370e5"
},
@@ -498,7 +461,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "362faf7a",
"metadata": {
"id": "b43937b6065d"
},
@@ -512,7 +474,6 @@
},
{
"cell_type": "markdown",
"id": "b69a6e67",
"metadata": {
"id": "09a6602bb745"
},
@@ -523,7 +484,6 @@
{
"cell_type": "code",
"execution_count": 16,
"id": "fd1b1361",
"metadata": {
"id": "2cacd9869ee5"
},
@@ -558,7 +518,6 @@
},
{
"cell_type": "markdown",
"id": "9501cb10",
"metadata": {
"id": "1124422cc200"
},
@@ -573,7 +532,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "e4d4a104",
"metadata": {
"id": "ed41c7712930"
},
@@ -597,7 +555,6 @@
},
{
"cell_type": "markdown",
"id": "09320b85",
"metadata": {
"id": "43088937e820"
},
@@ -612,7 +569,6 @@
{
"cell_type": "code",
"execution_count": 18,
"id": "096a368d",
"metadata": {
"id": "a0370bd840d2"
},
@@ -659,7 +615,6 @@
},
{
"cell_type": "markdown",
"id": "ef1ad223",
"metadata": {
"id": "ba45d58bf96e"
},
@@ -674,7 +629,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "70b5d9ea",
"metadata": {
"id": "9b01baa906b5"
},
@@ -692,7 +646,6 @@
{
"cell_type": "code",
"execution_count": 20,
"id": "7b6be5a8",
"metadata": {
"id": "9de878127530"
},
@@ -717,7 +670,6 @@
{
"cell_type": "code",
"execution_count": 21,
"id": "86888f38",
"metadata": {
"id": "95e408daf219"
},
@@ -790,7 +742,6 @@
},
{
"cell_type": "markdown",
"id": "4a9087dc",
"metadata": {
"id": "17f24794c9f0"
},
@@ -801,7 +752,6 @@
{
"cell_type": "code",
"execution_count": 22,
"id": "23bc4472",
"metadata": {
"id": "55a128883028"
},
@@ -825,7 +775,6 @@
},
{
"cell_type": "markdown",
"id": "56013644",
"metadata": {
"id": "aQIQSyF9GtSv"
},
@@ -837,23 +786,11 @@
},
{
"cell_type": "code",
"execution_count": 23,
"id": "f27d332b",
"execution_count": null,
"metadata": {
"id": "43aaff23416e"
},
"outputs": [
{
"data": {
"text/plain": [
"'/tmp/tmp969nj57e.json'"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"import tempfile\n",
"\n",
@@ -866,7 +803,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "49855575",
"metadata": {
"id": "307f468a3ecd"
},
@@ -901,7 +837,6 @@
},
{
"cell_type": "markdown",
"id": "da3f140d",
"metadata": {
"id": "QuVl8DrWG8NS"
},
@@ -912,7 +847,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "1ccb305d",
"metadata": {
"id": "3PgsA_vbI8Vg"
},
@@ -925,7 +859,6 @@
},
{
"cell_type": "markdown",
"id": "e8617e4a",
"metadata": {
"id": "mglUPwHpJH98"
},
@@ -935,7 +868,6 @@
},
{
"cell_type": "markdown",
"id": "6f4d35f2",
"metadata": {
"id": "qhIBCQ7dDSbW"
},
@@ -946,7 +878,6 @@
{
"cell_type": "code",
"execution_count": 26,
"id": "c5988e56",
"metadata": {
"id": "qiIg9b5zJLi1"
},
@@ -958,7 +889,6 @@
},
{
"cell_type": "markdown",
"id": "27cfc9a9",
"metadata": {
"id": "svLYiDf0OD2G"
},
@@ -971,7 +901,6 @@
{
"cell_type": "code",
"execution_count": 27,
"id": "d3ceb4f7",
"metadata": {
"id": "Y4zooldkGoM4"
},
@@ -985,7 +914,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "dc0170fc",
"metadata": {
"id": "xzY7TpUSJcTV"
},
@@ -1006,7 +934,6 @@
{
"cell_type": "code",
"execution_count": 29,
"id": "938b207e",
"metadata": {
"id": "17jrQi501QyX"
},
@@ -1029,7 +956,6 @@
},
{
"cell_type": "markdown",
"id": "f5275924",
"metadata": {
"id": "0f1a9fbecabb"
},
@@ -1040,7 +966,6 @@
{
"cell_type": "code",
"execution_count": 30,
"id": "920a1eba",
"metadata": {
"id": "1ddb70647d98"
},
@@ -1051,7 +976,6 @@
},
{
"cell_type": "markdown",
"id": "7c5264c8",
"metadata": {
"id": "qV2xjAnDDObD"
},
@@ -1062,7 +986,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "97bf5ec8",
"metadata": {
"id": "BpZQoJyxDlbO"
},
@@ -1080,7 +1003,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "8ebd3a67",
"metadata": {
"id": "QuARXzJVGyQX"
},
@@ -1095,7 +1017,6 @@
},
{
"cell_type": "markdown",
"id": "f6f6a5ab",
"metadata": {
"id": "np2cgVuuIe9k"
},
@@ -1105,7 +1026,6 @@
},
{
"cell_type": "markdown",
"id": "cf996223",
"metadata": {
"id": "8Ew1UgcIIiJG"
},
@@ -1116,7 +1036,6 @@
{
"cell_type": "code",
"execution_count": 33,
"id": "c0aa3fb2",
"metadata": {
"id": "nLOYTGygIlMK"
},
@@ -1128,7 +1047,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "09afc5a7",
"metadata": {
"id": "_uK4WOgqN1NG"
},
@@ -1143,20 +1061,18 @@
},
{
"cell_type": "markdown",
"id": "465e96d8",
"metadata": {
"id": "6LCGvBNvBd8D"
},
"source": [
"## Create Online Queries\n",
"\n",
"After you built your indexes, you may query against the deployed index to find nearest neighbours."
"After you built your indexes, you may query against the deployed index to find nearest neighbors."
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "9db18bd3",
"metadata": {
"id": "48e4e417a496"
},
@@ -1171,7 +1087,6 @@
{
"cell_type": "code",
"execution_count": 36,
"id": "17d8966f",
"metadata": {
"id": "A3KYVw5HB-4v"
},
@@ -1221,7 +1136,6 @@
},
{
"cell_type": "markdown",
"id": "4f84b7f8",
"metadata": {
"id": "c1116c7c0d7d"
},
@@ -1232,7 +1146,6 @@
{
"cell_type": "code",
"execution_count": 37,
"id": "5be36015",
"metadata": {
"id": "6f4ddb7c8d54"
},
@@ -1283,7 +1196,6 @@
},
{
"cell_type": "markdown",
"id": "ccd6484d",
"metadata": {
"id": "TpV-iwP9qw9c"
},
@@ -1298,7 +1210,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "4d511f7a",
"metadata": {
"id": "sx_vKniMq9ZX"
},
@@ -1311,7 +1222,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "e7bed20f",
"metadata": {
"id": "omj7N9iWv-Tq"
},