mirror of
https://github.com/GoogleCloudPlatform/vertex-ai-samples.git
synced 2026-09-26 14:42:04 +00:00
Ran linter
This commit is contained in:
+44
-14
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user