From 20902244def26ee87bb1ef18fd64f34edf2d4e85 Mon Sep 17 00:00:00 2001 From: "ivanmkc@google.com" Date: Wed, 15 Mar 2023 14:56:03 -0400 Subject: [PATCH] Ran linter --- ...ine_create_stack_overflow_embeddings.ipynb | 58 ++++++++++++++----- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/notebooks/official/matching_engine/sdk_matching_engine_create_stack_overflow_embeddings.ipynb b/notebooks/official/matching_engine/sdk_matching_engine_create_stack_overflow_embeddings.ipynb index 0bda6f2fc..c12b3a241 100644 --- a/notebooks/official/matching_engine/sdk_matching_engine_create_stack_overflow_embeddings.ipynb +++ b/notebooks/official/matching_engine/sdk_matching_engine_create_stack_overflow_embeddings.ipynb @@ -153,15 +153,19 @@ { "attachments": {}, "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "54ac7ebac10b" + }, "source": [ - "Install the latest version of redis for low-latency data retrieval" + "Install the latest version of Redis for low-latency data retrieval" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "e3dd53b3c06c" + }, "outputs": [], "source": [ "# Install the redis package\n", @@ -1111,10 +1115,12 @@ { "attachments": {}, "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "05514825ba7d" + }, "source": [ "## Storing and retrieving titles from a Redis data store\n", - "When you productionize this code into a service, you will need to conver the nearest nearest id's returned from Vertex AI Matching Engine into data usable by downstream services.\n", + "When you productionize this code into a service, you will need to convert the nearest nearest id's returned from Vertex AI Matching Engine into data usable by downstream services.\n", "\n", "In this case, you'll need to convert the id's to titles.\n", "\n", @@ -1126,7 +1132,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "5d2b240f0d52" + }, "outputs": [], "source": [ "REDIS_INSTANCE_NAME = \"stackoverflow-questions-unique\"\n", @@ -1138,18 +1146,31 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "371ccc0d2eb2" + }, "outputs": [], "source": [ "# Get host and port info\n", - "REDIS_HOST = ! gcloud redis instances list --region {REGION} --format='value(HOST)'\n", - "REDIS_PORT = ! gcloud redis instances list --region {REGION} --format='value(PORT)'" + "REDIS_HOST = ! gcloud redis instances list --filter=\"INSTANCE_NAME:'{REDIS_INSTANCE_NAME}'\" --region {REGION} --format='value(HOST)'\n", + "REDIS_PORT = ! gcloud redis instances list --filter=\"INSTANCE_NAME:'{REDIS_INSTANCE_NAME}'\" --region {REGION} --format='value(PORT)'\n", + "\n", + "if isinstance(REDIS_HOST, list):\n", + " REDIS_HOST = REDIS_HOST[0]\n", + "\n", + "if isinstance(REDIS_PORT, list):\n", + " REDIS_PORT = REDIS_PORT[0]\n", + "\n", + "print(f\"REDIS_HOST = {REDIS_HOST}\")\n", + "print(f\"REDIS_PORT = {REDIS_PORT}\")" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "73796089386a" + }, "outputs": [], "source": [ "# Connect to the instance\n", @@ -1161,7 +1182,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "f000f5432d13" + }, "outputs": [], "source": [ "# Convert the id -> title relationship into a dict and write to redis\n", @@ -1171,11 +1194,16 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "b1f8b396aeb1" + }, "outputs": [], "source": [ "# Verify that redis can retrieve the correct information\n", - "[f\"Actual = {title}, Retrieved = {redis_client.get(str(id))}\" for id, title in list(zip(df.id, df.title))[:10]]" + "[\n", + " f\"Actual = {title}, Retrieved = {redis_client.get(str(id))}\"\n", + " for id, title in list(zip(df.id, df.title))[:10]\n", + "]" ] }, { @@ -1218,7 +1246,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "d2fcf9468031" + }, "outputs": [], "source": [ "# Delete redis instance\n",