{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "gNz_7idNEdlE"
      },
      "outputs": [],
      "source": [
        "# Copyright 2026 Google LLC\n",
        "#\n",
        "# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
        "# you may not use this file except in compliance with the License.\n",
        "# You may obtain a copy of the License at\n",
        "#\n",
        "#     https://www.apache.org/licenses/LICENSE-2.0\n",
        "#\n",
        "# Unless required by applicable law or agreed to in writing, software\n",
        "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
        "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
        "# See the License for the specific language governing permissions and\n",
        "# limitations under the License."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "IXbw-R0ZGiWf"
      },
      "source": [
        "# Analyzing movie posters in BigQuery with Gemini\n",
        "\n",
        "<table align=\"left\">\n",
        "  <td style=\"text-align: center\">\n",
        "    <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/generative-ai/blob/main/gemini/use-cases/applying-llms-to-data/analyze-poster-images-in-bigquery/poster_image_analysis.ipynb\">\n",
        "      <img width=\"32px\" src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Google Colaboratory logo\"><br> Open in Colab\n",
        "    </a>\n",
        "  </td>\n",
        "  <td style=\"text-align: center\">\n",
        "    <a href=\"https://console.cloud.google.com/vertex-ai/colab/import/https:%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fgenerative-ai%2Fmain%2Fgemini%2Fuse-cases%2Fapplying-llms-to-data%2Fanalyze-poster-images-in-bigquery%2Fposter_image_analysis.ipynb\">\n",
        "      <img width=\"32px\" src=\"https://lh3.googleusercontent.com/JmcxdQi-qOpctIvWKgPtrzZdJJK-J3sWE1RsfjZNwshCFgE_9fULcNpuXYTilIR2hjwN\" alt=\"Google Cloud Colab Enterprise logo\"><br> Open in Colab Enterprise\n",
        "    </a>\n",
        "  </td>\n",
        "  <td style=\"text-align: center\">\n",
        "    <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/generative-ai/main/gemini/use-cases/applying-llms-to-data/analyze-poster-images-in-bigquery/poster_image_analysis.ipynb\">\n",
        "      <img src=\"https://www.gstatic.com/images/branding/gcpiconscolors/vertexai/v1/32px.svg\" alt=\"Vertex AI logo\"><br> Open in Vertex AI Workbench\n",
        "    </a>\n",
        "  </td>\n",
        "  <td style=\"text-align: center\">\n",
        "    <a href=\"https://console.cloud.google.com/bigquery/import?url=https://github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/use-cases/applying-llms-to-data/analyze-poster-images-in-bigquery/poster_image_analysis.ipynb\">\n",
        "      <img src=\"https://www.gstatic.com/images/branding/gcpiconscolors/bigquery/v1/32px.svg\" alt=\"BigQuery Studio logo\"><br> Open in BigQuery Studio\n",
        "    </a>\n",
        "  </td>\n",
        "  <td style=\"text-align: center\">\n",
        "    <a href=\"https://github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/use-cases/applying-llms-to-data/analyze-poster-images-in-bigquery/poster_image_analysis.ipynb\">\n",
        "      <img width=\"32px\" src=\"https://raw.githubusercontent.com/primer/octicons/refs/heads/main/icons/mark-github-24.svg\" alt=\"GitHub logo\"><br> View on GitHub\n",
        "    </a>\n",
        "  </td>\n",
        "</table>\n",
        "\n",
        "<div style=\"clear: both;\"></div>\n",
        "\n",
        "<b>Share to:</b>\n",
        "\n",
        "<a href=\"https://www.linkedin.com/sharing/share-offsite/?url=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/use-cases/applying-llms-to-data/analyze-poster-images-in-bigquery/poster_image_analysis.ipynb\" target=\"_blank\">\n",
        "  <img width=\"20px\" src=\"https://upload.wikimedia.org/wikipedia/commons/8/81/LinkedIn_icon.svg\" alt=\"LinkedIn logo\">\n",
        "</a>\n",
        "\n",
        "<a href=\"https://bsky.app/intent/compose?text=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/use-cases/applying-llms-to-data/analyze-poster-images-in-bigquery/poster_image_analysis.ipynb\" target=\"_blank\">\n",
        "  <img width=\"20px\" src=\"https://upload.wikimedia.org/wikipedia/commons/7/7a/Bluesky_Logo.svg\" alt=\"Bluesky logo\">\n",
        "</a>\n",
        "\n",
        "<a href=\"https://twitter.com/intent/tweet?url=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/use-cases/applying-llms-to-data/analyze-poster-images-in-bigquery/poster_image_analysis.ipynb\" target=\"_blank\">\n",
        "  <img width=\"20px\" src=\"https://upload.wikimedia.org/wikipedia/commons/5/5a/X_icon_2.svg\" alt=\"X logo\">\n",
        "</a>\n",
        "\n",
        "<a href=\"https://reddit.com/submit?url=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/use-cases/applying-llms-to-data/analyze-poster-images-in-bigquery/poster_image_analysis.ipynb\" target=\"_blank\">\n",
        "  <img width=\"20px\" src=\"https://redditinc.com/hubfs/Reddit%20Inc/Brand/Reddit_Logo.png\" alt=\"Reddit logo\">\n",
        "</a>\n",
        "\n",
        "<a href=\"https://www.facebook.com/sharer/sharer.php?u=https%3A//github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/use-cases/applying-llms-to-data/analyze-poster-images-in-bigquery/poster_image_analysis.ipynb\" target=\"_blank\">\n",
        "  <img width=\"20px\" src=\"https://upload.wikimedia.org/wikipedia/commons/5/51/Facebook_f_logo_%282019%29.svg\" alt=\"Facebook logo\">\n",
        "</a>            "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "4qTZ1THsriwh"
      },
      "source": [
        "| Author |\n",
        "| --- |\n",
        "| [Alicia Williams](https://github.com/aliciawilliams) |"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_cGtn8TvG7SB"
      },
      "source": [
        "## Overview\n",
        "\n",
        "The objective is to demonstrate how to use the Gemini models for analysis in BigQuery, including:\n",
        "\n",
        "\n",
        "*   Completing setup steps for accessing Vertex AI (including Gemini models) from BigQuery\n",
        "*   Creating an Object Table for the unstructured dataset being analyzed\n",
        "*   Performing analysis over the object table using the Gemini model\n",
        "*   Joining analysis results back to structured table for deeper insights\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "sf3ioTDBzuHR"
      },
      "source": [
        "## About the dataset\n",
        "\n",
        "The dataset of movie poster images used in this demo are stored in a public Google Cloud Storage bucket: [`gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters`](https://console.cloud.google.com/storage/browser/cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters)\n",
        "\n",
        "![Movie Posters](https://storage.googleapis.com/github-repo/generative-ai/gemini/use-cases/applying-llms-to-data/movie-posters.jpeg)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "E8sI7ir1fVgI"
      },
      "source": [
        "## Services and Costs\n",
        "\n",
        "This tutorial uses the following Google Cloud data analytics and ML services, they are billable components of Google Cloud:\n",
        "\n",
        "* BigQuery & BigQuery ML [(pricing)](https://cloud.google.com/bigquery/pricing)\n",
        "* Vertex AI API [(pricing)](https://cloud.google.com/vertex-ai/pricing)\n",
        "\n",
        "Use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "P10XEmXlzeOF"
      },
      "source": [
        "# Setup steps for accessing Cloud Storage and Vertex AI models from BigQuery"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6xxnNycUFs8Z"
      },
      "source": [
        "## Enable the Vertex AI and BigQuery Connection APIs"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "82RF-HLRFhVn"
      },
      "outputs": [],
      "source": [
        "!gcloud services enable aiplatform.googleapis.com bigqueryconnection.googleapis.com"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-_fb9Y_t94a_"
      },
      "source": [
        "## Create a Cloud resource connection\n",
        "\n",
        "*Note: This demo analyzes a dataset that sits in a public Cloud Storage bucket. When analyzing a dataset in a non-public bucket, the service account associated with the Cloud resource connection will also need \"Storage Object Viewer\" role on that storage bucket using [these instructions](https://docs.cloud.google.com/bigquery/docs/create-cloud-resource-connection#access-storage).*"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "zHgqlk3B95BE"
      },
      "outputs": [],
      "source": [
        "!bq mk --connection --location=us \\\n",
        "    --connection_type=CLOUD_RESOURCE gemini_conn"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "B-fcQvmo8bcU"
      },
      "source": [
        "## Configure end user permissions\n",
        "\n",
        "In order to run a query job that calls a Vertex AI model, your user account needs the following IAM roles:\n",
        "\n",
        "* BigQuery Job User (`roles/bigquery.jobUser`)\n",
        "\n",
        "* Vertex AI User (`roles/aiplatform.user`)\n",
        "\n",
        "You can follow [these instructions](https://docs.cloud.google.com/bigquery/docs/permissions-for-ai-functions#grant_the_required_roles_to_the_user_or_group) for how to grant these roles.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0TU6VxJA9bRI"
      },
      "source": [
        "# Create an object table for the movie poster images"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "fm840uHo4kHP"
      },
      "source": [
        "## Create a new dataset named `'gemini_demo'`"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "fdSiqoR04jeQ"
      },
      "outputs": [],
      "source": [
        "%%bigquery\n",
        "CREATE SCHEMA\n",
        "  `gemini_demo` OPTIONS (location = 'US');"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "PaLtG8c3GZFi"
      },
      "source": [
        "## Create an object table referencing Google Cloud Storage bucket"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "T97do1tjGZsm"
      },
      "outputs": [],
      "source": [
        "%%bigquery\n",
        "CREATE OR REPLACE EXTERNAL TABLE\n",
        "  `gemini_demo.movie_posters`\n",
        "WITH CONNECTION `us.gemini_conn`\n",
        "OPTIONS (\n",
        "  object_metadata = 'SIMPLE',\n",
        "  uris = ['gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/*']\n",
        "  );"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {
        "id": "Xqh_kLTcYR2n"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "Query is running:   0%|          |"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/plain": [
              "Downloading:   0%|          |"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "summary": "{\n  \"name\": \"get_ipython()\",\n  \"rows\": 5,\n  \"fields\": [\n    {\n      \"column\": \"uri\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 5,\n        \"samples\": [\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/barque_sortant_du_port.jpeg\",\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/der_student_von_prag.jpg\",\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/battling_butler.jpg\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"generation\",\n      \"properties\": {\n        \"dtype\": \"Int64\",\n        \"num_unique_values\": 5,\n        \"samples\": [\n          1683653080024577,\n          1683653080624441,\n          1683653080233711\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"content_type\",\n      \"properties\": {\n        \"dtype\": \"category\",\n        \"num_unique_values\": 1,\n        \"samples\": [\n          \"image/jpeg\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"size\",\n      \"properties\": {\n        \"dtype\": \"Int64\",\n        \"num_unique_values\": 5,\n        \"samples\": [\n          30086\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"md5_hash\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 5,\n        \"samples\": [\n          \"1a831e349e8f954abc9fabe120fb9220\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"updated\",\n      \"properties\": {\n        \"dtype\": \"date\",\n        \"min\": \"2023-05-09 17:24:39.856000+00:00\",\n        \"max\": \"2023-05-09 17:24:40.669000+00:00\",\n        \"num_unique_values\": 5,\n        \"samples\": [\n          \"2023-05-09 17:24:40.069000+00:00\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"metadata\",\n      \"properties\": {\n        \"dtype\": \"object\",\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"ref\",\n      \"properties\": {\n        \"dtype\": \"object\",\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    }\n  ]\n}",
              "type": "dataframe"
            },
            "text/html": [
              "\n",
              "  <div id=\"df-233a7fe8-0e99-4c1e-b3fe-d2bf5af614b1\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>uri</th>\n",
              "      <th>generation</th>\n",
              "      <th>content_type</th>\n",
              "      <th>size</th>\n",
              "      <th>md5_hash</th>\n",
              "      <th>updated</th>\n",
              "      <th>metadata</th>\n",
              "      <th>ref</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>1683653079811418</td>\n",
              "      <td>image/jpeg</td>\n",
              "      <td>81952</td>\n",
              "      <td>8b48292aba74c3c1812ca7bdd0be7fa7</td>\n",
              "      <td>2023-05-09 17:24:39.856000+00:00</td>\n",
              "      <td>[]</td>\n",
              "      <td>{'uri': 'gs://cloud-samples-data/vertex-ai/dat...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>1683653080024577</td>\n",
              "      <td>image/jpeg</td>\n",
              "      <td>30086</td>\n",
              "      <td>1a831e349e8f954abc9fabe120fb9220</td>\n",
              "      <td>2023-05-09 17:24:40.069000+00:00</td>\n",
              "      <td>[]</td>\n",
              "      <td>{'uri': 'gs://cloud-samples-data/vertex-ai/dat...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>1683653080233711</td>\n",
              "      <td>image/jpeg</td>\n",
              "      <td>147585</td>\n",
              "      <td>c18dd6e6a87d75a95801c47f97545706</td>\n",
              "      <td>2023-05-09 17:24:40.280000+00:00</td>\n",
              "      <td>[]</td>\n",
              "      <td>{'uri': 'gs://cloud-samples-data/vertex-ai/dat...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>1683653080449371</td>\n",
              "      <td>image/jpeg</td>\n",
              "      <td>107821</td>\n",
              "      <td>93d93b6aacb9b1d8ace3c037d683a961</td>\n",
              "      <td>2023-05-09 17:24:40.495000+00:00</td>\n",
              "      <td>[]</td>\n",
              "      <td>{'uri': 'gs://cloud-samples-data/vertex-ai/dat...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>1683653080624441</td>\n",
              "      <td>image/jpeg</td>\n",
              "      <td>96294</td>\n",
              "      <td>c78573f7f29b9da284b1a2dda85654e9</td>\n",
              "      <td>2023-05-09 17:24:40.669000+00:00</td>\n",
              "      <td>[]</td>\n",
              "      <td>{'uri': 'gs://cloud-samples-data/vertex-ai/dat...</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-233a7fe8-0e99-4c1e-b3fe-d2bf5af614b1')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-233a7fe8-0e99-4c1e-b3fe-d2bf5af614b1 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-233a7fe8-0e99-4c1e-b3fe-d2bf5af614b1');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-24ac9f10-25be-4ea9-a4ac-a383e4a9f742\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-24ac9f10-25be-4ea9-a4ac-a383e4a9f742')\"\n",
              "            title=\"Suggest charts\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-24ac9f10-25be-4ea9-a4ac-a383e4a9f742 button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ],
            "text/plain": [
              "                                                 uri        generation  \\\n",
              "0  gs://cloud-samples-data/vertex-ai/dataset-mana...  1683653079811418   \n",
              "1  gs://cloud-samples-data/vertex-ai/dataset-mana...  1683653080024577   \n",
              "2  gs://cloud-samples-data/vertex-ai/dataset-mana...  1683653080233711   \n",
              "3  gs://cloud-samples-data/vertex-ai/dataset-mana...  1683653080449371   \n",
              "4  gs://cloud-samples-data/vertex-ai/dataset-mana...  1683653080624441   \n",
              "\n",
              "  content_type    size                          md5_hash  \\\n",
              "0   image/jpeg   81952  8b48292aba74c3c1812ca7bdd0be7fa7   \n",
              "1   image/jpeg   30086  1a831e349e8f954abc9fabe120fb9220   \n",
              "2   image/jpeg  147585  c18dd6e6a87d75a95801c47f97545706   \n",
              "3   image/jpeg  107821  93d93b6aacb9b1d8ace3c037d683a961   \n",
              "4   image/jpeg   96294  c78573f7f29b9da284b1a2dda85654e9   \n",
              "\n",
              "                           updated metadata  \\\n",
              "0 2023-05-09 17:24:39.856000+00:00       []   \n",
              "1 2023-05-09 17:24:40.069000+00:00       []   \n",
              "2 2023-05-09 17:24:40.280000+00:00       []   \n",
              "3 2023-05-09 17:24:40.495000+00:00       []   \n",
              "4 2023-05-09 17:24:40.669000+00:00       []   \n",
              "\n",
              "                                                 ref  \n",
              "0  {'uri': 'gs://cloud-samples-data/vertex-ai/dat...  \n",
              "1  {'uri': 'gs://cloud-samples-data/vertex-ai/dat...  \n",
              "2  {'uri': 'gs://cloud-samples-data/vertex-ai/dat...  \n",
              "3  {'uri': 'gs://cloud-samples-data/vertex-ai/dat...  \n",
              "4  {'uri': 'gs://cloud-samples-data/vertex-ai/dat...  "
            ]
          },
          "execution_count": 5,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "%%bigquery\n",
        "SELECT * FROM `gemini_demo.movie_posters` LIMIT 5"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "JcYVG4qNKAuY"
      },
      "source": [
        "# Perform analysis on the movie poster images"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "KCZ-nme8GjTN"
      },
      "source": [
        "## Prompt Gemini to analyze the movie poster image object table"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "iLN9ecDLXJPe"
      },
      "outputs": [],
      "source": [
        "%%bigquery\n",
        "CREATE OR REPLACE TABLE\n",
        "  `gemini_demo.movie_posters_results` AS (\n",
        "  SELECT\n",
        "    uri,\n",
        "    STRING(OBJ.GET_ACCESS_URL(ref,'r').access_urls.read_url) AS signed_url,\n",
        "    AI.GENERATE(\n",
        "      prompt => ('What is the movie title and year of release for this poster?', OBJ.GET_ACCESS_URL(ref, 'r')),\n",
        "      output_schema => 'title STRING, year INT64'\n",
        "    ).* EXCEPT(full_response,status)\n",
        "  FROM\n",
        "    `gemini_demo.movie_posters`\n",
        ");"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {
        "id": "8bcyGsNWHPeZ"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "Query is running:   0%|          |"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/plain": [
              "Downloading:   0%|          |"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "summary": "{\n  \"name\": \"get_ipython()\",\n  \"rows\": 19,\n  \"fields\": [\n    {\n      \"column\": \"uri\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/barque_sortant_du_port.jpeg\",\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/shoulder_arms.jpeg\",\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/little_annie_rooney.jpg\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"signed_url\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          \"https://storage.googleapis.com/cloud-samples-data/vertex-ai%2Fdataset-management%2Fdatasets%2Fclassic-movie-posters%2Fbarque_sortant_du_port.jpeg?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=bqcx-735508242970-dy4t%40gcp-sa-bigquery-condel.iam.gserviceaccount.com%2F20260227%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20260227T212652Z&X-Goog-Expires=21600&X-Goog-SignedHeaders=host&generation=1683653080024577&X-Goog-Signature=6461a0202b488317133e0413080a2afb07ba2936abee619958ff2ed4bad61de1ce80db6bd44598e783fea15809c1fea6ef3daccb78940f20cf42fdaadd614d5739aff3353cddcac4b0d2f41b117f34ebc53b97f18c4cc995da7b389c25ae0e6d923b018bc0f5d2e8200ce47e01bf22fba8c30cc59b2f6f33abbce44142fbda8d0f358debb2d97607155a4505c559f70f918741de76da570973852d7d3d51433051fb39944cd86006182a72ab7fe7dddb59669e40ab4f9d4b59e8b8c0182cc76fbad230a7db98d741f106cfb5b17f9f8c03858d2f1479cd4794b619d633117df2c8cb77c7c8c50f2cf8b8026e9776e2c0d8d81a80909532e5f1545c53de7ded1f\",\n          \"https://storage.googleapis.com/cloud-samples-data/vertex-ai%2Fdataset-management%2Fdatasets%2Fclassic-movie-posters%2Fshoulder_arms.jpeg?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=bqcx-735508242970-dy4t%40gcp-sa-bigquery-condel.iam.gserviceaccount.com%2F20260227%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20260227T212652Z&X-Goog-Expires=21600&X-Goog-SignedHeaders=host&generation=1683653082560296&X-Goog-Signature=930dbf0a667ebd04d760f51cefad2807ecdd10476d453c1e3c57ccbbd3ba3555c8b60f0bd5075536c96f690ed740ab4b2e098a9bb7c6d2705f16811cdf23e239121fa08cd748e2547809d21ceb0724fe606dd0c212df7588320ab8ccc0b1c5e69c1fd69645706d25de1db6c6d45dbc230dbb59d32906015c228e6b0cdf17facc9907d19cef8c97f0ef01f0722af9389f124aadb4433d87a4715f9a052bcff1a80a5497a2b9c9a09c57f23ab67d46abbd4c7f602e7c2f406e4616c53a337446f4e0ac55e2e322c3ff95515a47d8b94b524d6c551c2d0ac72364fb17670bf1fa58c3cc7051f78ceadd04d8e5d29b8eb4121b9179ada3882a3e41f9571b70a5601f\",\n          \"https://storage.googleapis.com/cloud-samples-data/vertex-ai%2Fdataset-management%2Fdatasets%2Fclassic-movie-posters%2Flittle_annie_rooney.jpg?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=bqcx-735508242970-dy4t%40gcp-sa-bigquery-condel.iam.gserviceaccount.com%2F20260227%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20260227T212652Z&X-Goog-Expires=21600&X-Goog-SignedHeaders=host&generation=1683653081385488&X-Goog-Signature=98fb370979cf232710e31a73fd8fcbe7dcaf39e07b71db3beebeedd8717b68bca854883fb4e249bc520e761680c08cec0b180aa7060f0f69f16a4bc1a5d0e27cbe9447eaa3c93191d4a91e3ff197a632e979f7ae1117aa01f427115c9e14494371f593605663c5e71b8e4f7662a05f210141367ed4b3c3b8e65ea78b4c6fc00e801e145f5e168b3e0bfc695cdbec1b1435f17c723cf12049ccafaad3d185a51ad2446e6f11fe5c483362db53d3fb6efec2fbd87f0400f3f84bad6d32f788ed07747e1509e92a09b38ece0c500169148aaf96160932bc9ca1f57529126979dad97c96d1cb87409255d1a9d82350e1958352ce767b8db5588a327c26d1ef1cd928\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"title\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          \"Barque sortant du port\",\n          \"Shoulder Arms\",\n          \"Little Annie Rooney\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"year\",\n      \"properties\": {\n        \"dtype\": \"Int64\",\n        \"num_unique_values\": 13,\n        \"samples\": [\n          1927,\n          1925,\n          1895\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    }\n  ]\n}",
              "type": "dataframe"
            },
            "text/html": [
              "\n",
              "  <div id=\"df-50b3e479-a895-48da-adde-0ad675108498\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>uri</th>\n",
              "      <th>signed_url</th>\n",
              "      <th>title</th>\n",
              "      <th>year</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>Barque sortant du port</td>\n",
              "      <td>1895</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>The Great Train Robbery</td>\n",
              "      <td>1903</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>Mabel's Busy Day</td>\n",
              "      <td>1914</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>Les Vampires</td>\n",
              "      <td>1915</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>He Did and He Didn't</td>\n",
              "      <td>1916</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>Shoulder Arms</td>\n",
              "      <td>1918</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>Little Lord Fauntleroy</td>\n",
              "      <td>1921</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>Felix in Hollywood</td>\n",
              "      <td>1923</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>West of Hot Dog</td>\n",
              "      <td>1924</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>AU SECOURS!</td>\n",
              "      <td>1924</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>Sally of the Sawdust</td>\n",
              "      <td>1925</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>Little Annie Rooney</td>\n",
              "      <td>1925</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>The Lost World</td>\n",
              "      <td>1925</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>Der Student von Prag</td>\n",
              "      <td>1926</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>Battling Butler</td>\n",
              "      <td>1926</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>Brown of Harvard</td>\n",
              "      <td>1926</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>Putting Pants on Philip</td>\n",
              "      <td>1927</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>The Beloved Rogue</td>\n",
              "      <td>1927</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>https://storage.googleapis.com/cloud-samples-d...</td>\n",
              "      <td>The Merry Widow</td>\n",
              "      <td>1934</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-50b3e479-a895-48da-adde-0ad675108498')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-50b3e479-a895-48da-adde-0ad675108498 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-50b3e479-a895-48da-adde-0ad675108498');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-2786d1aa-c024-47b8-b76e-16b038c30844\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-2786d1aa-c024-47b8-b76e-16b038c30844')\"\n",
              "            title=\"Suggest charts\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-2786d1aa-c024-47b8-b76e-16b038c30844 button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ],
            "text/plain": [
              "                                                  uri  \\\n",
              "0   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "1   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "2   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "3   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "4   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "5   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "6   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "7   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "8   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "9   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "10  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "11  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "12  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "13  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "14  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "15  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "16  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "17  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "18  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "\n",
              "                                           signed_url  \\\n",
              "0   https://storage.googleapis.com/cloud-samples-d...   \n",
              "1   https://storage.googleapis.com/cloud-samples-d...   \n",
              "2   https://storage.googleapis.com/cloud-samples-d...   \n",
              "3   https://storage.googleapis.com/cloud-samples-d...   \n",
              "4   https://storage.googleapis.com/cloud-samples-d...   \n",
              "5   https://storage.googleapis.com/cloud-samples-d...   \n",
              "6   https://storage.googleapis.com/cloud-samples-d...   \n",
              "7   https://storage.googleapis.com/cloud-samples-d...   \n",
              "8   https://storage.googleapis.com/cloud-samples-d...   \n",
              "9   https://storage.googleapis.com/cloud-samples-d...   \n",
              "10  https://storage.googleapis.com/cloud-samples-d...   \n",
              "11  https://storage.googleapis.com/cloud-samples-d...   \n",
              "12  https://storage.googleapis.com/cloud-samples-d...   \n",
              "13  https://storage.googleapis.com/cloud-samples-d...   \n",
              "14  https://storage.googleapis.com/cloud-samples-d...   \n",
              "15  https://storage.googleapis.com/cloud-samples-d...   \n",
              "16  https://storage.googleapis.com/cloud-samples-d...   \n",
              "17  https://storage.googleapis.com/cloud-samples-d...   \n",
              "18  https://storage.googleapis.com/cloud-samples-d...   \n",
              "\n",
              "                      title  year  \n",
              "0    Barque sortant du port  1895  \n",
              "1   The Great Train Robbery  1903  \n",
              "2          Mabel's Busy Day  1914  \n",
              "3              Les Vampires  1915  \n",
              "4      He Did and He Didn't  1916  \n",
              "5             Shoulder Arms  1918  \n",
              "6    Little Lord Fauntleroy  1921  \n",
              "7        Felix in Hollywood  1923  \n",
              "8           West of Hot Dog  1924  \n",
              "9               AU SECOURS!  1924  \n",
              "10     Sally of the Sawdust  1925  \n",
              "11      Little Annie Rooney  1925  \n",
              "12           The Lost World  1925  \n",
              "13     Der Student von Prag  1926  \n",
              "14          Battling Butler  1926  \n",
              "15         Brown of Harvard  1926  \n",
              "16  Putting Pants on Philip  1927  \n",
              "17        The Beloved Rogue  1927  \n",
              "18          The Merry Widow  1934  "
            ]
          },
          "execution_count": 9,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "%%bigquery\n",
        "SELECT * FROM `gemini_demo.movie_posters_results`"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "M4swkWSH08yE"
      },
      "source": [
        "## Prompt Gemini to provide movie summaries for each movie poster image"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 18,
      "metadata": {
        "id": "TxRXjZbAZyI8"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "Query is running:   0%|          |"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/plain": [
              "Downloading:   0%|          |"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "summary": "{\n  \"name\": \"get_ipython()\",\n  \"rows\": 19,\n  \"fields\": [\n    {\n      \"column\": \"uri\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/mabels_busy_day.jpeg\",\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/little_annie_rooney.jpg\",\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/barque_sortant_du_port.jpeg\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"title\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          \"Mabel's Busy Day\",\n          \"Little Annie Rooney\",\n          \"Barque sortant du port\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"year\",\n      \"properties\": {\n        \"dtype\": \"Int64\",\n        \"num_unique_values\": 13,\n        \"samples\": [\n          1923,\n          1895,\n          1914\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"movie_summary\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          \"In \\\"Mabel's Busy Day\\\" (1914), Mabel Normand plays a struggling hot dog vendor at a busy racetrack. Her attempts to sell her frankfurters are constantly thwarted and complicated by the arrival of Charlie Chaplin's mischievous Tramp character.\\n\\nThe hungry Tramp repeatedly tries to steal Mabel's hot dogs, leading to a series of comedic misunderstandings, chases, and typical Keystone slapstick antics as Mabel tries to protect her livelihood from the persistent thief and the general chaos of the day.\",\n          \"\\\"Little Annie Rooney\\\" (1925) stars Mary Pickford as the titular character, a feisty and independent tomboy growing up in a tough, working-class Irish-American neighborhood in New York. Her beloved father is a respected police officer.\\n\\nAnnie often finds herself in the middle of street brawls between rival youth gangs. Tragedy strikes when her father is accidentally killed during one such gang altercation. Devastated and seeking justice, Annie initially vows revenge. However, she finds an unexpected ally and eventual love interest in Tony Harrison, a young man from one of the rival factions.\\n\\nThe film follows Annie's journey from grief and anger towards understanding and forgiveness, ultimately leading to a resolution that sees her embrace a more mature role and find happiness amidst the challenges of her community. It's a classic Mary Pickford vehicle, showcasing her energetic persona in a story of street-level drama and enduring love.\",\n          \"\\\"Barque sortant du port\\\" (Boat Leaving the Port) is a short, silent, black-and-white documentary film from 1895, produced by the **Lumi\\u00e8re Brothers**.\\n\\nIt features a single, static shot of a small sailboat (a \\\"barque\\\") being pushed out of a harbor or quay by several men using poles. The film captures a simple, everyday scene of manual labor and maritime activity, showcasing the nascent art of cinema's ability to record real-life events. It is one of the very earliest films ever made.\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    }\n  ]\n}",
              "type": "dataframe"
            },
            "text/html": [
              "\n",
              "  <div id=\"df-0f8c92fa-a664-4206-b12a-3cec95634609\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>uri</th>\n",
              "      <th>title</th>\n",
              "      <th>year</th>\n",
              "      <th>movie_summary</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Mabel's Busy Day</td>\n",
              "      <td>1914</td>\n",
              "      <td>In \"Mabel's Busy Day\" (1914), Mabel Normand pl...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>He Did and He Didn't</td>\n",
              "      <td>1916</td>\n",
              "      <td>\"He Did and He Didn't\" (1916) is a silent slap...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Der Student von Prag</td>\n",
              "      <td>1926</td>\n",
              "      <td>\"Der Student von Prag\" (1926) is a classic Ger...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>The Lost World</td>\n",
              "      <td>1925</td>\n",
              "      <td>The 1925 silent film **The Lost World** is bas...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Shoulder Arms</td>\n",
              "      <td>1918</td>\n",
              "      <td>Charlie Chaplin stars as a bumbling, raw Ameri...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Little Annie Rooney</td>\n",
              "      <td>1925</td>\n",
              "      <td>\"Little Annie Rooney\" (1925) stars Mary Pickfo...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>The Beloved Rogue</td>\n",
              "      <td>1927</td>\n",
              "      <td>\"The Beloved Rogue\" (1927) stars John Barrymor...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>The Great Train Robbery</td>\n",
              "      <td>1903</td>\n",
              "      <td>\"The Great Train Robbery\" (1903) is a landmark...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Little Lord Fauntleroy</td>\n",
              "      <td>1921</td>\n",
              "      <td>The 1921 silent film *Little Lord Fauntleroy* ...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>West of Hot Dog</td>\n",
              "      <td>1924</td>\n",
              "      <td>\"West of Hot Dog\" is a 1924 silent Western com...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Battling Butler</td>\n",
              "      <td>1926</td>\n",
              "      <td>The 1926 silent comedy **Battling Butler** sta...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Barque sortant du port</td>\n",
              "      <td>1895</td>\n",
              "      <td>\"Barque sortant du port\" (Boat Leaving the Por...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Les Vampires</td>\n",
              "      <td>1915</td>\n",
              "      <td>**Les Vampires** is a 1915 French silent crime...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Felix in Hollywood</td>\n",
              "      <td>1923</td>\n",
              "      <td>In the 1923 animated short **\"Felix in Hollywo...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Sally of the Sawdust</td>\n",
              "      <td>1925</td>\n",
              "      <td>The 1925 silent film **Sally of the Sawdust** ...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Brown of Harvard</td>\n",
              "      <td>1926</td>\n",
              "      <td>The 1926 silent film **\"Brown of Harvard\"** st...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Putting Pants on Philip</td>\n",
              "      <td>1927</td>\n",
              "      <td>\"Putting Pants on Philip,\" a 1927 silent film,...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>The Merry Widow</td>\n",
              "      <td>1934</td>\n",
              "      <td>Ernst Lubitsch's 1934 musical comedy **The Mer...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>AU SECOURS!</td>\n",
              "      <td>1924</td>\n",
              "      <td>The 1924 French silent film **AU SECOURS!** (H...</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-0f8c92fa-a664-4206-b12a-3cec95634609')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-0f8c92fa-a664-4206-b12a-3cec95634609 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-0f8c92fa-a664-4206-b12a-3cec95634609');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-ff59110b-4447-49c9-b364-81abe4168d3b\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-ff59110b-4447-49c9-b364-81abe4168d3b')\"\n",
              "            title=\"Suggest charts\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-ff59110b-4447-49c9-b364-81abe4168d3b button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ],
            "text/plain": [
              "                                                  uri  \\\n",
              "0   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "1   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "2   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "3   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "4   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "5   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "6   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "7   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "8   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "9   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "10  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "11  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "12  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "13  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "14  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "15  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "16  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "17  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "18  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "\n",
              "                      title  year  \\\n",
              "0          Mabel's Busy Day  1914   \n",
              "1      He Did and He Didn't  1916   \n",
              "2      Der Student von Prag  1926   \n",
              "3            The Lost World  1925   \n",
              "4             Shoulder Arms  1918   \n",
              "5       Little Annie Rooney  1925   \n",
              "6         The Beloved Rogue  1927   \n",
              "7   The Great Train Robbery  1903   \n",
              "8    Little Lord Fauntleroy  1921   \n",
              "9           West of Hot Dog  1924   \n",
              "10          Battling Butler  1926   \n",
              "11   Barque sortant du port  1895   \n",
              "12             Les Vampires  1915   \n",
              "13       Felix in Hollywood  1923   \n",
              "14     Sally of the Sawdust  1925   \n",
              "15         Brown of Harvard  1926   \n",
              "16  Putting Pants on Philip  1927   \n",
              "17          The Merry Widow  1934   \n",
              "18              AU SECOURS!  1924   \n",
              "\n",
              "                                        movie_summary  \n",
              "0   In \"Mabel's Busy Day\" (1914), Mabel Normand pl...  \n",
              "1   \"He Did and He Didn't\" (1916) is a silent slap...  \n",
              "2   \"Der Student von Prag\" (1926) is a classic Ger...  \n",
              "3   The 1925 silent film **The Lost World** is bas...  \n",
              "4   Charlie Chaplin stars as a bumbling, raw Ameri...  \n",
              "5   \"Little Annie Rooney\" (1925) stars Mary Pickfo...  \n",
              "6   \"The Beloved Rogue\" (1927) stars John Barrymor...  \n",
              "7   \"The Great Train Robbery\" (1903) is a landmark...  \n",
              "8   The 1921 silent film *Little Lord Fauntleroy* ...  \n",
              "9   \"West of Hot Dog\" is a 1924 silent Western com...  \n",
              "10  The 1926 silent comedy **Battling Butler** sta...  \n",
              "11  \"Barque sortant du port\" (Boat Leaving the Por...  \n",
              "12  **Les Vampires** is a 1915 French silent crime...  \n",
              "13  In the 1923 animated short **\"Felix in Hollywo...  \n",
              "14  The 1925 silent film **Sally of the Sawdust** ...  \n",
              "15  The 1926 silent film **\"Brown of Harvard\"** st...  \n",
              "16  \"Putting Pants on Philip,\" a 1927 silent film,...  \n",
              "17  Ernst Lubitsch's 1934 musical comedy **The Mer...  \n",
              "18  The 1924 French silent film **AU SECOURS!** (H...  "
            ]
          },
          "execution_count": 18,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "%%bigquery\n",
        "SELECT\n",
        "  uri,\n",
        "  title,\n",
        "  year,\n",
        "  AI.GENERATE(\n",
        "    prompt => ('Provide a short summary of movie titled ' || title || ' from the year ' || year)\n",
        "    ).result AS movie_summary\n",
        "FROM\n",
        "  `gemini_demo.movie_posters_results`"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Vj7gGTPy2qpQ"
      },
      "source": [
        "# Join analysis results with structured data for deeper insights\n",
        "Using text embeddings to perform similarity joins of movie poster images to a movie reviews dataset in BigQuery"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "woZDvRuV11IQ"
      },
      "source": [
        "## Generate text embeddings for title and year associated with movie posters"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "VbC6MUnEbN8q"
      },
      "outputs": [],
      "source": [
        "%%bigquery\n",
        "CREATE OR REPLACE TABLE\n",
        "  `gemini_demo.movie_posters_results_embeddings` AS (\n",
        "  SELECT\n",
        "    title,\n",
        "    year,\n",
        "    uri,\n",
        "    AI.EMBED(\n",
        "      content => 'The movie titled ' || title || ' from the year ' || year,\n",
        "      endpoint => 'gemini-embedding-001'\n",
        "    ).result AS embedding\n",
        "  FROM\n",
        "    `gemini_demo.movie_posters_results`\n",
        ");"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "id": "0PDZT8T52B95"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "Query is running:   0%|          |"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/plain": [
              "Downloading:   0%|          |"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "summary": "{\n  \"name\": \"get_ipython()\",\n  \"rows\": 5,\n  \"fields\": [\n    {\n      \"column\": \"title\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 5,\n        \"samples\": [\n          \"The Great Train Robbery\",\n          \"He Did and He Didn't\",\n          \"Mabel's Busy Day\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"year\",\n      \"properties\": {\n        \"dtype\": \"Int64\",\n        \"num_unique_values\": 5,\n        \"samples\": [\n          1903,\n          1916,\n          1914\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"uri\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 5,\n        \"samples\": [\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/the_great_train_robbery.jpg\",\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/he_did_and_he_didnt.jpeg\",\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/mabels_busy_day.jpeg\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"embedding\",\n      \"properties\": {\n        \"dtype\": \"object\",\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    }\n  ]\n}",
              "type": "dataframe"
            },
            "text/html": [
              "\n",
              "  <div id=\"df-7bfee387-12a3-4191-8143-90ed9f800f2e\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>title</th>\n",
              "      <th>year</th>\n",
              "      <th>uri</th>\n",
              "      <th>embedding</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Barque sortant du port</td>\n",
              "      <td>1895</td>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>[-0.01909666322171688, 0.005955183878540993, -...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>The Great Train Robbery</td>\n",
              "      <td>1903</td>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>[-0.021316001191735268, -0.012172936461865902,...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Mabel's Busy Day</td>\n",
              "      <td>1914</td>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>[-0.024318691343069077, -0.000487475743284449,...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Les Vampires</td>\n",
              "      <td>1915</td>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>[-0.025294441729784012, 0.017817920073866844, ...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>He Did and He Didn't</td>\n",
              "      <td>1916</td>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>[-0.022868528962135315, 0.009465230628848076, ...</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-7bfee387-12a3-4191-8143-90ed9f800f2e')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-7bfee387-12a3-4191-8143-90ed9f800f2e button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-7bfee387-12a3-4191-8143-90ed9f800f2e');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-9b722c3f-94ad-4e54-981e-fbd4473e6a9e\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-9b722c3f-94ad-4e54-981e-fbd4473e6a9e')\"\n",
              "            title=\"Suggest charts\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-9b722c3f-94ad-4e54-981e-fbd4473e6a9e button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ],
            "text/plain": [
              "                     title  year  \\\n",
              "0   Barque sortant du port  1895   \n",
              "1  The Great Train Robbery  1903   \n",
              "2         Mabel's Busy Day  1914   \n",
              "3             Les Vampires  1915   \n",
              "4     He Did and He Didn't  1916   \n",
              "\n",
              "                                                 uri  \\\n",
              "0  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "1  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "2  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "3  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "4  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "\n",
              "                                           embedding  \n",
              "0  [-0.01909666322171688, 0.005955183878540993, -...  \n",
              "1  [-0.021316001191735268, -0.012172936461865902,...  \n",
              "2  [-0.024318691343069077, -0.000487475743284449,...  \n",
              "3  [-0.025294441729784012, 0.017817920073866844, ...  \n",
              "4  [-0.022868528962135315, 0.009465230628848076, ...  "
            ]
          },
          "execution_count": 12,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "%%bigquery\n",
        "SELECT * FROM `gemini_demo.movie_posters_results_embeddings` LIMIT 5"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "7UUZPBpuGHPO"
      },
      "source": [
        "## Generate text embeddings for subset of IMDB dataset"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "4Jh7AJ2pIZuB"
      },
      "outputs": [],
      "source": [
        "%%bigquery\n",
        "# Create table containing movie_id, title, and year for movies in IMDB reviews dataset that were release prior to 1935\n",
        "CREATE OR REPLACE VIEW\n",
        "  `gemini_demo.imdb_movies` AS (\n",
        "  WITH\n",
        "    reviews AS (\n",
        "      SELECT\n",
        "        reviews.movie_id AS movie_id,\n",
        "        title.primary_title AS title,\n",
        "        title.start_year AS year,\n",
        "        reviews.review AS review\n",
        "      FROM\n",
        "        `bigquery-public-data.imdb.reviews` reviews\n",
        "      LEFT JOIN\n",
        "        `bigquery-public-data.imdb.title_basics` title\n",
        "      ON\n",
        "        reviews.movie_id = title.tconst)\n",
        "  SELECT\n",
        "    DISTINCT(movie_id),\n",
        "    title,\n",
        "    year\n",
        "  FROM\n",
        "    reviews\n",
        "  WHERE\n",
        "    year < 1935)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "9yzdx5W5czgd"
      },
      "outputs": [],
      "source": [
        "%%bigquery\n",
        "CREATE OR REPLACE TABLE\n",
        "  `gemini_demo.imdb_movies_embeddings` AS (\n",
        "  SELECT\n",
        "    title,\n",
        "    year,\n",
        "    movie_id,\n",
        "    AI.EMBED(\n",
        "      content => 'The movie titled ' || title || ' from the year ' || year,\n",
        "      endpoint => 'gemini-embedding-001'\n",
        "    ).result AS embedding\n",
        "  FROM\n",
        "    `gemini_demo.imdb_movies`\n",
        ");"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "metadata": {
        "id": "a9t-8ZfCdUIk"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "Query is running:   0%|          |"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/plain": [
              "Downloading:   0%|          |"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "summary": "{\n  \"name\": \"get_ipython()\",\n  \"rows\": 5,\n  \"fields\": [\n    {\n      \"column\": \"title\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 5,\n        \"samples\": [\n          \"Leaving the Factory\",\n          \"Rough Sea at Dover\",\n          \"Boat Leaving the Port\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"year\",\n      \"properties\": {\n        \"dtype\": \"Int64\",\n        \"num_unique_values\": 2,\n        \"samples\": [\n          1895,\n          1894\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"movie_id\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 5,\n        \"samples\": [\n          \"tt0000010\",\n          \"tt0000030\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"embedding\",\n      \"properties\": {\n        \"dtype\": \"object\",\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    }\n  ]\n}",
              "type": "dataframe"
            },
            "text/html": [
              "\n",
              "  <div id=\"df-9e0a08be-cd26-4ec1-b89d-14a2bfc778e5\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>title</th>\n",
              "      <th>year</th>\n",
              "      <th>movie_id</th>\n",
              "      <th>embedding</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Dickson Experimental Sound Film</td>\n",
              "      <td>1894</td>\n",
              "      <td>tt0177707</td>\n",
              "      <td>[-0.011816445738077164, -0.041168369352817535,...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Leaving the Factory</td>\n",
              "      <td>1895</td>\n",
              "      <td>tt0000010</td>\n",
              "      <td>[-0.011916860938072205, 0.015054121613502502, ...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Boat Leaving the Port</td>\n",
              "      <td>1895</td>\n",
              "      <td>tt0000016</td>\n",
              "      <td>[-0.029500054195523262, 0.005711852107197046, ...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>The Execution of Mary, Queen of Scots</td>\n",
              "      <td>1895</td>\n",
              "      <td>tt0132134</td>\n",
              "      <td>[-0.024642348289489746, 0.024970047175884247, ...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Rough Sea at Dover</td>\n",
              "      <td>1895</td>\n",
              "      <td>tt0000030</td>\n",
              "      <td>[-0.007878931239247322, 0.027580272406339645, ...</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-9e0a08be-cd26-4ec1-b89d-14a2bfc778e5')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-9e0a08be-cd26-4ec1-b89d-14a2bfc778e5 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-9e0a08be-cd26-4ec1-b89d-14a2bfc778e5');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-eddf61f7-e6d1-4dec-bf99-3ae0522dd5d7\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-eddf61f7-e6d1-4dec-bf99-3ae0522dd5d7')\"\n",
              "            title=\"Suggest charts\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-eddf61f7-e6d1-4dec-bf99-3ae0522dd5d7 button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ],
            "text/plain": [
              "                                   title  year   movie_id  \\\n",
              "0        Dickson Experimental Sound Film  1894  tt0177707   \n",
              "1                    Leaving the Factory  1895  tt0000010   \n",
              "2                  Boat Leaving the Port  1895  tt0000016   \n",
              "3  The Execution of Mary, Queen of Scots  1895  tt0132134   \n",
              "4                     Rough Sea at Dover  1895  tt0000030   \n",
              "\n",
              "                                           embedding  \n",
              "0  [-0.011816445738077164, -0.041168369352817535,...  \n",
              "1  [-0.011916860938072205, 0.015054121613502502, ...  \n",
              "2  [-0.029500054195523262, 0.005711852107197046, ...  \n",
              "3  [-0.024642348289489746, 0.024970047175884247, ...  \n",
              "4  [-0.007878931239247322, 0.027580272406339645, ...  "
            ]
          },
          "execution_count": 15,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "%%bigquery\n",
        "SELECT * FROM `gemini_demo.imdb_movies_embeddings` LIMIT 5"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1SZ1OmVc2IN5"
      },
      "source": [
        "## Match movie poster images to IMDB `movie_id` using BigQuery `VECTOR_SEARCH`"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 16,
      "metadata": {
        "id": "N4pBoQPP2Y3k"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "Query is running:   0%|          |"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/plain": [
              "Downloading:   0%|          |"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "summary": "{\n  \"name\": \"get_ipython()\",\n  \"rows\": 19,\n  \"fields\": [\n    {\n      \"column\": \"poster_uri\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/putting_paints_on_philip.jpeg\",\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/sally_of_the_sawdust.jpg\",\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/battling_butler.jpg\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"poster_title\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          \"Putting Pants on Philip\",\n          \"Sally of the Sawdust\",\n          \"Battling Butler\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"poster_year\",\n      \"properties\": {\n        \"dtype\": \"Int64\",\n        \"num_unique_values\": 13,\n        \"samples\": [\n          1915,\n          1914,\n          1927\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"imdb_title\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          \"Putting Pants on Philip\",\n          \"Sally of the Sawdust\",\n          \"Battling Butler\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"imdb_year\",\n      \"properties\": {\n        \"dtype\": \"Int64\",\n        \"num_unique_values\": 13,\n        \"samples\": [\n          1915,\n          1913,\n          1927\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"imdb_movie_id\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          \"tt0018294\",\n          \"tt0016308\",\n          \"tt0016630\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"distance\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 0.06310667859438789,\n        \"min\": 0.0,\n        \"max\": 0.18508910419754754,\n        \"num_unique_values\": 5,\n        \"samples\": [\n          0.15144097037365933,\n          0.09469846438580964,\n          0.18508910419754754\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    }\n  ]\n}",
              "type": "dataframe"
            },
            "text/html": [
              "\n",
              "  <div id=\"df-d6f401e3-d25c-482e-abde-fc7d27293b0b\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>poster_uri</th>\n",
              "      <th>poster_title</th>\n",
              "      <th>poster_year</th>\n",
              "      <th>imdb_title</th>\n",
              "      <th>imdb_year</th>\n",
              "      <th>imdb_movie_id</th>\n",
              "      <th>distance</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Putting Pants on Philip</td>\n",
              "      <td>1927</td>\n",
              "      <td>Putting Pants on Philip</td>\n",
              "      <td>1927</td>\n",
              "      <td>tt0018294</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Little Lord Fauntleroy</td>\n",
              "      <td>1921</td>\n",
              "      <td>Little Lord Fauntleroy</td>\n",
              "      <td>1921</td>\n",
              "      <td>tt0012397</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Shoulder Arms</td>\n",
              "      <td>1918</td>\n",
              "      <td>Shoulder Arms</td>\n",
              "      <td>1918</td>\n",
              "      <td>tt0009611</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Brown of Harvard</td>\n",
              "      <td>1926</td>\n",
              "      <td>Brown of Harvard</td>\n",
              "      <td>1926</td>\n",
              "      <td>tt0016690</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>The Merry Widow</td>\n",
              "      <td>1934</td>\n",
              "      <td>The Merry Widow</td>\n",
              "      <td>1925</td>\n",
              "      <td>tt0016104</td>\n",
              "      <td>0.151441</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Sally of the Sawdust</td>\n",
              "      <td>1925</td>\n",
              "      <td>Sally of the Sawdust</td>\n",
              "      <td>1925</td>\n",
              "      <td>tt0016308</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>He Did and He Didn't</td>\n",
              "      <td>1916</td>\n",
              "      <td>He Did and He Didn't</td>\n",
              "      <td>1916</td>\n",
              "      <td>tt0006764</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>AU SECOURS!</td>\n",
              "      <td>1924</td>\n",
              "      <td>Help!</td>\n",
              "      <td>1924</td>\n",
              "      <td>tt0013845</td>\n",
              "      <td>0.185089</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>The Great Train Robbery</td>\n",
              "      <td>1903</td>\n",
              "      <td>The Great Train Robbery</td>\n",
              "      <td>1903</td>\n",
              "      <td>tt0000439</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Mabel's Busy Day</td>\n",
              "      <td>1914</td>\n",
              "      <td>Mabel's Busy Day</td>\n",
              "      <td>1914</td>\n",
              "      <td>tt0004280</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>The Beloved Rogue</td>\n",
              "      <td>1927</td>\n",
              "      <td>The Beloved Rogue</td>\n",
              "      <td>1927</td>\n",
              "      <td>tt0017667</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Battling Butler</td>\n",
              "      <td>1926</td>\n",
              "      <td>Battling Butler</td>\n",
              "      <td>1926</td>\n",
              "      <td>tt0016630</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>West of Hot Dog</td>\n",
              "      <td>1924</td>\n",
              "      <td>West of Hot Dog</td>\n",
              "      <td>1924</td>\n",
              "      <td>tt0015477</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Little Annie Rooney</td>\n",
              "      <td>1925</td>\n",
              "      <td>Little Annie Rooney</td>\n",
              "      <td>1925</td>\n",
              "      <td>tt0016028</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Der Student von Prag</td>\n",
              "      <td>1926</td>\n",
              "      <td>The Student of Prague</td>\n",
              "      <td>1913</td>\n",
              "      <td>tt0003419</td>\n",
              "      <td>0.153324</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Barque sortant du port</td>\n",
              "      <td>1895</td>\n",
              "      <td>Boat Leaving the Port</td>\n",
              "      <td>1895</td>\n",
              "      <td>tt0000016</td>\n",
              "      <td>0.094698</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>The Lost World</td>\n",
              "      <td>1925</td>\n",
              "      <td>The Lost World</td>\n",
              "      <td>1925</td>\n",
              "      <td>tt0016039</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Les Vampires</td>\n",
              "      <td>1915</td>\n",
              "      <td>Les Vampires</td>\n",
              "      <td>1915</td>\n",
              "      <td>tt0006206</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Felix in Hollywood</td>\n",
              "      <td>1923</td>\n",
              "      <td>Felix in Hollywood</td>\n",
              "      <td>1923</td>\n",
              "      <td>tt0017871</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-d6f401e3-d25c-482e-abde-fc7d27293b0b')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-d6f401e3-d25c-482e-abde-fc7d27293b0b button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-d6f401e3-d25c-482e-abde-fc7d27293b0b');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-54fbb365-5c68-4882-93ef-e9069c4aacc9\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-54fbb365-5c68-4882-93ef-e9069c4aacc9')\"\n",
              "            title=\"Suggest charts\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-54fbb365-5c68-4882-93ef-e9069c4aacc9 button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ],
            "text/plain": [
              "                                           poster_uri  \\\n",
              "0   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "1   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "2   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "3   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "4   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "5   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "6   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "7   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "8   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "9   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "10  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "11  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "12  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "13  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "14  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "15  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "16  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "17  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "18  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "\n",
              "               poster_title  poster_year               imdb_title  imdb_year  \\\n",
              "0   Putting Pants on Philip         1927  Putting Pants on Philip       1927   \n",
              "1    Little Lord Fauntleroy         1921   Little Lord Fauntleroy       1921   \n",
              "2             Shoulder Arms         1918            Shoulder Arms       1918   \n",
              "3          Brown of Harvard         1926         Brown of Harvard       1926   \n",
              "4           The Merry Widow         1934          The Merry Widow       1925   \n",
              "5      Sally of the Sawdust         1925     Sally of the Sawdust       1925   \n",
              "6      He Did and He Didn't         1916     He Did and He Didn't       1916   \n",
              "7               AU SECOURS!         1924                    Help!       1924   \n",
              "8   The Great Train Robbery         1903  The Great Train Robbery       1903   \n",
              "9          Mabel's Busy Day         1914         Mabel's Busy Day       1914   \n",
              "10        The Beloved Rogue         1927        The Beloved Rogue       1927   \n",
              "11          Battling Butler         1926          Battling Butler       1926   \n",
              "12          West of Hot Dog         1924          West of Hot Dog       1924   \n",
              "13      Little Annie Rooney         1925      Little Annie Rooney       1925   \n",
              "14     Der Student von Prag         1926    The Student of Prague       1913   \n",
              "15   Barque sortant du port         1895    Boat Leaving the Port       1895   \n",
              "16           The Lost World         1925           The Lost World       1925   \n",
              "17             Les Vampires         1915             Les Vampires       1915   \n",
              "18       Felix in Hollywood         1923       Felix in Hollywood       1923   \n",
              "\n",
              "   imdb_movie_id  distance  \n",
              "0      tt0018294  0.000000  \n",
              "1      tt0012397  0.000000  \n",
              "2      tt0009611  0.000000  \n",
              "3      tt0016690  0.000000  \n",
              "4      tt0016104  0.151441  \n",
              "5      tt0016308  0.000000  \n",
              "6      tt0006764  0.000000  \n",
              "7      tt0013845  0.185089  \n",
              "8      tt0000439  0.000000  \n",
              "9      tt0004280  0.000000  \n",
              "10     tt0017667  0.000000  \n",
              "11     tt0016630  0.000000  \n",
              "12     tt0015477  0.000000  \n",
              "13     tt0016028  0.000000  \n",
              "14     tt0003419  0.153324  \n",
              "15     tt0000016  0.094698  \n",
              "16     tt0016039  0.000000  \n",
              "17     tt0006206  0.000000  \n",
              "18     tt0017871  0.000000  "
            ]
          },
          "execution_count": 16,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "%%bigquery\n",
        "SELECT\n",
        "  query.uri AS poster_uri,\n",
        "  query.title AS poster_title,\n",
        "  query.year AS poster_year,\n",
        "  base.title AS imdb_title,\n",
        "  base.year AS imdb_year,\n",
        "  base.movie_id AS imdb_movie_id,\n",
        "  distance\n",
        "FROM\n",
        "  VECTOR_SEARCH( TABLE `gemini_demo.imdb_movies_embeddings`,\n",
        "    'embedding',\n",
        "    TABLE `gemini_demo.movie_posters_results_embeddings`,\n",
        "    'embedding',\n",
        "    top_k => 1,\n",
        "    distance_type => 'COSINE');"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "RCoxBtpSLxNi"
      },
      "source": [
        "Now let's join some additional information on ratings..."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 17,
      "metadata": {
        "id": "pbz_nMtdY7S6"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "Query is running:   0%|          |"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "text/plain": [
              "Downloading:   0%|          |"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "summary": "{\n  \"name\": \"get_ipython()\",\n  \"rows\": 19,\n  \"fields\": [\n    {\n      \"column\": \"poster_uri\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/shoulder_arms.jpeg\",\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/the_beloved_rogue.jpeg\",\n          \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/classic-movie-posters/felix_in_hollywood.jpeg\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"poster_title\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          \"Shoulder Arms\",\n          \"The Beloved Rogue\",\n          \"Felix in Hollywood\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"poster_year\",\n      \"properties\": {\n        \"dtype\": \"Int64\",\n        \"num_unique_values\": 13,\n        \"samples\": [\n          1895,\n          1923,\n          1918\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"imdb_title\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          \"Shoulder Arms\",\n          \"The Beloved Rogue\",\n          \"Felix in Hollywood\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"imdb_year\",\n      \"properties\": {\n        \"dtype\": \"Int64\",\n        \"num_unique_values\": 13,\n        \"samples\": [\n          1895,\n          1913,\n          1918\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"imdb_movie_id\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          \"tt0009611\",\n          \"tt0017667\",\n          \"tt0017871\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"distance\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 0.06310667859438797,\n        \"min\": 0.0,\n        \"max\": 0.18508910419754754,\n        \"num_unique_values\": 5,\n        \"samples\": [\n          0.15144097037365933,\n          0.09469846438580964,\n          0.18508910419754754\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"average_rating\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 0.5610141193457283,\n        \"min\": 5.4,\n        \"max\": 7.3,\n        \"num_unique_values\": 12,\n        \"samples\": [\n          5.5,\n          5.9,\n          7.3\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"num_votes\",\n      \"properties\": {\n        \"dtype\": \"Int64\",\n        \"num_unique_values\": 19,\n        \"samples\": [\n          7965,\n          980,\n          1093\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    }\n  ]\n}",
              "type": "dataframe"
            },
            "text/html": [
              "\n",
              "  <div id=\"df-9978a413-1f5a-49b2-b350-1ddb3874463f\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>poster_uri</th>\n",
              "      <th>poster_title</th>\n",
              "      <th>poster_year</th>\n",
              "      <th>imdb_title</th>\n",
              "      <th>imdb_year</th>\n",
              "      <th>imdb_movie_id</th>\n",
              "      <th>distance</th>\n",
              "      <th>average_rating</th>\n",
              "      <th>num_votes</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Shoulder Arms</td>\n",
              "      <td>1918</td>\n",
              "      <td>Shoulder Arms</td>\n",
              "      <td>1918</td>\n",
              "      <td>tt0009611</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>7.3</td>\n",
              "      <td>7965</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Les Vampires</td>\n",
              "      <td>1915</td>\n",
              "      <td>Les Vampires</td>\n",
              "      <td>1915</td>\n",
              "      <td>tt0006206</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>7.3</td>\n",
              "      <td>5857</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>The Great Train Robbery</td>\n",
              "      <td>1903</td>\n",
              "      <td>The Great Train Robbery</td>\n",
              "      <td>1903</td>\n",
              "      <td>tt0000439</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>7.2</td>\n",
              "      <td>22637</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>The Merry Widow</td>\n",
              "      <td>1934</td>\n",
              "      <td>The Merry Widow</td>\n",
              "      <td>1925</td>\n",
              "      <td>tt0016104</td>\n",
              "      <td>0.151441</td>\n",
              "      <td>7.2</td>\n",
              "      <td>2729</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>The Lost World</td>\n",
              "      <td>1925</td>\n",
              "      <td>The Lost World</td>\n",
              "      <td>1925</td>\n",
              "      <td>tt0016039</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>7.0</td>\n",
              "      <td>6527</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>The Beloved Rogue</td>\n",
              "      <td>1927</td>\n",
              "      <td>The Beloved Rogue</td>\n",
              "      <td>1927</td>\n",
              "      <td>tt0017667</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>7.0</td>\n",
              "      <td>980</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Battling Butler</td>\n",
              "      <td>1926</td>\n",
              "      <td>Battling Butler</td>\n",
              "      <td>1926</td>\n",
              "      <td>tt0016630</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>7.0</td>\n",
              "      <td>4373</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Little Annie Rooney</td>\n",
              "      <td>1925</td>\n",
              "      <td>Little Annie Rooney</td>\n",
              "      <td>1925</td>\n",
              "      <td>tt0016028</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>6.8</td>\n",
              "      <td>1121</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>AU SECOURS!</td>\n",
              "      <td>1924</td>\n",
              "      <td>Help!</td>\n",
              "      <td>1924</td>\n",
              "      <td>tt0013845</td>\n",
              "      <td>0.185089</td>\n",
              "      <td>6.8</td>\n",
              "      <td>552</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Little Lord Fauntleroy</td>\n",
              "      <td>1921</td>\n",
              "      <td>Little Lord Fauntleroy</td>\n",
              "      <td>1921</td>\n",
              "      <td>tt0012397</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>6.7</td>\n",
              "      <td>396</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Sally of the Sawdust</td>\n",
              "      <td>1925</td>\n",
              "      <td>Sally of the Sawdust</td>\n",
              "      <td>1925</td>\n",
              "      <td>tt0016308</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>6.6</td>\n",
              "      <td>633</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Felix in Hollywood</td>\n",
              "      <td>1923</td>\n",
              "      <td>Felix in Hollywood</td>\n",
              "      <td>1923</td>\n",
              "      <td>tt0017871</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>6.5</td>\n",
              "      <td>1093</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Putting Pants on Philip</td>\n",
              "      <td>1927</td>\n",
              "      <td>Putting Pants on Philip</td>\n",
              "      <td>1927</td>\n",
              "      <td>tt0018294</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>6.5</td>\n",
              "      <td>1176</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Der Student von Prag</td>\n",
              "      <td>1926</td>\n",
              "      <td>The Student of Prague</td>\n",
              "      <td>1913</td>\n",
              "      <td>tt0003419</td>\n",
              "      <td>0.153324</td>\n",
              "      <td>6.4</td>\n",
              "      <td>2679</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>He Did and He Didn't</td>\n",
              "      <td>1916</td>\n",
              "      <td>He Did and He Didn't</td>\n",
              "      <td>1916</td>\n",
              "      <td>tt0006764</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>6.4</td>\n",
              "      <td>360</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Brown of Harvard</td>\n",
              "      <td>1926</td>\n",
              "      <td>Brown of Harvard</td>\n",
              "      <td>1926</td>\n",
              "      <td>tt0016690</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>6.2</td>\n",
              "      <td>1573</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Barque sortant du port</td>\n",
              "      <td>1895</td>\n",
              "      <td>Boat Leaving the Port</td>\n",
              "      <td>1895</td>\n",
              "      <td>tt0000016</td>\n",
              "      <td>0.094698</td>\n",
              "      <td>5.9</td>\n",
              "      <td>1707</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>West of Hot Dog</td>\n",
              "      <td>1924</td>\n",
              "      <td>West of Hot Dog</td>\n",
              "      <td>1924</td>\n",
              "      <td>tt0015477</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>5.5</td>\n",
              "      <td>335</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>gs://cloud-samples-data/vertex-ai/dataset-mana...</td>\n",
              "      <td>Mabel's Busy Day</td>\n",
              "      <td>1914</td>\n",
              "      <td>Mabel's Busy Day</td>\n",
              "      <td>1914</td>\n",
              "      <td>tt0004280</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>5.4</td>\n",
              "      <td>1141</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-9978a413-1f5a-49b2-b350-1ddb3874463f')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-9978a413-1f5a-49b2-b350-1ddb3874463f button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-9978a413-1f5a-49b2-b350-1ddb3874463f');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-80fa6a48-7050-48ae-954f-de410bdc512b\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-80fa6a48-7050-48ae-954f-de410bdc512b')\"\n",
              "            title=\"Suggest charts\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-80fa6a48-7050-48ae-954f-de410bdc512b button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ],
            "text/plain": [
              "                                           poster_uri  \\\n",
              "0   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "1   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "2   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "3   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "4   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "5   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "6   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "7   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "8   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "9   gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "10  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "11  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "12  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "13  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "14  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "15  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "16  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "17  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "18  gs://cloud-samples-data/vertex-ai/dataset-mana...   \n",
              "\n",
              "               poster_title  poster_year               imdb_title  imdb_year  \\\n",
              "0             Shoulder Arms         1918            Shoulder Arms       1918   \n",
              "1              Les Vampires         1915             Les Vampires       1915   \n",
              "2   The Great Train Robbery         1903  The Great Train Robbery       1903   \n",
              "3           The Merry Widow         1934          The Merry Widow       1925   \n",
              "4            The Lost World         1925           The Lost World       1925   \n",
              "5         The Beloved Rogue         1927        The Beloved Rogue       1927   \n",
              "6           Battling Butler         1926          Battling Butler       1926   \n",
              "7       Little Annie Rooney         1925      Little Annie Rooney       1925   \n",
              "8               AU SECOURS!         1924                    Help!       1924   \n",
              "9    Little Lord Fauntleroy         1921   Little Lord Fauntleroy       1921   \n",
              "10     Sally of the Sawdust         1925     Sally of the Sawdust       1925   \n",
              "11       Felix in Hollywood         1923       Felix in Hollywood       1923   \n",
              "12  Putting Pants on Philip         1927  Putting Pants on Philip       1927   \n",
              "13     Der Student von Prag         1926    The Student of Prague       1913   \n",
              "14     He Did and He Didn't         1916     He Did and He Didn't       1916   \n",
              "15         Brown of Harvard         1926         Brown of Harvard       1926   \n",
              "16   Barque sortant du port         1895    Boat Leaving the Port       1895   \n",
              "17          West of Hot Dog         1924          West of Hot Dog       1924   \n",
              "18         Mabel's Busy Day         1914         Mabel's Busy Day       1914   \n",
              "\n",
              "   imdb_movie_id  distance  average_rating  num_votes  \n",
              "0      tt0009611  0.000000             7.3       7965  \n",
              "1      tt0006206  0.000000             7.3       5857  \n",
              "2      tt0000439  0.000000             7.2      22637  \n",
              "3      tt0016104  0.151441             7.2       2729  \n",
              "4      tt0016039  0.000000             7.0       6527  \n",
              "5      tt0017667  0.000000             7.0        980  \n",
              "6      tt0016630  0.000000             7.0       4373  \n",
              "7      tt0016028  0.000000             6.8       1121  \n",
              "8      tt0013845  0.185089             6.8        552  \n",
              "9      tt0012397  0.000000             6.7        396  \n",
              "10     tt0016308  0.000000             6.6        633  \n",
              "11     tt0017871  0.000000             6.5       1093  \n",
              "12     tt0018294  0.000000             6.5       1176  \n",
              "13     tt0003419  0.153324             6.4       2679  \n",
              "14     tt0006764  0.000000             6.4        360  \n",
              "15     tt0016690  0.000000             6.2       1573  \n",
              "16     tt0000016  0.094698             5.9       1707  \n",
              "17     tt0015477  0.000000             5.5        335  \n",
              "18     tt0004280  0.000000             5.4       1141  "
            ]
          },
          "execution_count": 17,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "%%bigquery\n",
        "SELECT\n",
        "  query.uri AS poster_uri,\n",
        "  query.title AS poster_title,\n",
        "  query.year AS poster_year,\n",
        "  base.title AS imdb_title,\n",
        "  base.year AS imdb_year,\n",
        "  base.movie_id AS imdb_movie_id,\n",
        "  distance,\n",
        "  imdb.average_rating,\n",
        "  imdb.num_votes\n",
        "FROM\n",
        "  VECTOR_SEARCH( TABLE `gemini_demo.imdb_movies_embeddings`,\n",
        "    'embedding',\n",
        "    TABLE `gemini_demo.movie_posters_results_embeddings`,\n",
        "    'embedding',\n",
        "    top_k => 1,\n",
        "    distance_type => 'COSINE') DATA\n",
        "LEFT JOIN\n",
        "  `bigquery-public-data.imdb.title_ratings` imdb\n",
        "ON\n",
        "  base.movie_id = imdb.tconst\n",
        "ORDER BY\n",
        "  imdb.average_rating DESC"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "UB8VKTHJJlKx"
      },
      "source": [
        "# Cleaning up\n",
        "\n",
        "To clean up all Google Cloud resources used in this project, you can [delete the Google Cloud project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects) you used for the tutorial.\n",
        "\n",
        "Otherwise, you can delete the individual resources you created in this tutorial by uncommenting the below:"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "nSF-ZhhPMjfs"
      },
      "outputs": [],
      "source": [
        "#\n",
        "# !bq rm -r -f $PROJECT_ID:gemini_demo\n",
        "#"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "gFWBsvpbhGtE"
      },
      "source": [
        "# Wrap up\n",
        "\n",
        "In this you have seen an example of how to integrate BigQuery with Vertex AI LLMs, and given examples of how the `AI.GENERATE` function can be applied directly to multimodal data stored in BigQuery, as well as how to generate embeddings with `AI.EMBED`.\n",
        "\n",
        "Check out our BigQuery documentation on [generating text](https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-ai-generate) and [generating embeddings](https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-ai-embed) to learn more about generative AI in BigQuery."
      ]
    }
  ],
  "metadata": {
    "colab": {
      "name": "poster_image_analysis.ipynb",
      "toc_visible": true
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
