使用 SQL、物件資料表和 BigQuery DataFrame 分析多模態資料

本教學課程說明如何使用 SQL 查詢、AI.GENERATE 函式AI.EMBED 函式BigQuery DataFrames分析 Cymbal 寵物商店公開資料集中的多模態資料

AI.GENERATE 函式可讓您分析任何結構化和非結構化資料的組合,AI.EMBED 函式則可讓您從 BigQuery 中的文字或圖片資料建立嵌入

您可以使用 VECTOR_SEARCH 函式尋找類似圖片。VECTOR_SEARCH 函式可對嵌入執行語意搜尋或混合搜尋,找出類似的實體。

本教學課程使用持續性物件表格,儲存 ObjectRef 值。

目標

  • 在 BigQuery 資料表中,使用 ObjectRef 值將圖片資料與結構化資料一併儲存。
  • 使用 AI.GENERATE 函式擴充資料。
  • 使用 AI.EMBED 函式,根據圖片資料生成嵌入項目。
  • 使用 VECTOR_SEARCH 函式尋找類似圖片。
  • 使用 ObjectRef 值陣列來摘要使用者手冊。

費用

在本文件中,您會使用下列 Google Cloud的計費元件:

  • BigQuery: you incur costs for the data that you process in BigQuery.
  • Cloud Storage: you incur costs for reading the objects stored in Cloud Storage.
  • Gemini Enterprise Agent Platform: you incur costs for calls to Agent Platform models.

如要根據預測用量估算費用,請使用 Pricing Calculator

初次使用 Google Cloud 的使用者可能符合免費試用期資格。

如要進一步瞭解費用,請參閱下列定價頁面:

事前準備

  1. 在 Google Cloud 控制台的專案選擇器頁面中,選取或建立 Google Cloud 專案。

    選取或建立專案所需的角色

    • 選取專案:選取專案時,不需要具備特定 IAM 角色,只要您在專案中獲派角色,即可選取該專案。
    • 建立專案:如要建立專案,您需要「專案建立者」角色 (roles/resourcemanager.projectCreator),其中包含 resourcemanager.projects.create 權限。瞭解如何授予角色

    前往專案選取器

  2. 確認專案已啟用計費功能 Google Cloud

  3. 啟用 BigQuery、BigQuery Connection、Cloud Storage 和 Agent Platform API。

    啟用 API 時所需的角色

    如要啟用 API,您必須具備 serviceusage.services.enable 權限。如果您建立了專案,可能已透過「擁有者」角色 (roles/owner) 取得這項權限。否則,您可以透過「服務使用情形管理員」角色 (roles/serviceusage.serviceUsageAdmin) 取得這項權限。瞭解如何授予角色

    啟用 API

必要的角色

如要取得完成本教學課程所需的權限,請要求管理員授予您下列 IAM 角色:

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

您或許也能透過自訂角色或其他預先定義的角色,取得必要權限。

建立資料集、資料表、模型和連線

在本節中,您會建立本教學課程中使用的資料集、連線、資料表和模型。

建立資料集

建立 BigQuery 資料集,內含您在本教學課程中建立的物件,方法如下:

控制台

  1. 前往 Google Cloud 控制台的「BigQuery」頁面。

    前往「BigQuery」

  2. 點選左側窗格中的 「Explorer」

    醒目顯示的「Explorer」窗格按鈕。

    如果沒有看到左側窗格,請按一下 「Expand left pane」(展開左側窗格),開啟窗格。

  3. 在「Explorer」中展開專案,然後按一下「Datasets」

  4. 在「資料集」頁面,按一下 「建立資料集」

  5. 在「建立資料集」頁面中,執行下列操作:

    1. 在「Dataset ID」(資料集 ID) 中輸入 cymbal_pets

    2. 選取「資料位置」的「美國」

    3. 其餘設定請保留預設狀態,然後按一下「建立資料集」

SQL

使用 CREATE SCHEMA 陳述式

  1. 前往 Google Cloud 控制台的「BigQuery」頁面。

    前往「BigQuery」

  2. 在查詢編輯器中輸入下列陳述式:

    CREATE SCHEMA PROJECT_ID.cymbal_pets
      OPTIONS (
        description = 'Dataset for BigQuery ML tutorial',
        location = 'US');

    PROJECT_ID 替換為您的專案 ID。

  3. 按一下「執行」

如要進一步瞭解如何執行查詢,請參閱「執行互動式查詢」。

您會收到類似以下的確認訊息:The dataset named cymbal_pets was created.

建立連線

建立Cloud 資源連線,並取得連線的服務帳戶。BigQuery 會使用連線存取 Cloud Storage 中的物件。

  1. 點選左側窗格中的 「Explorer」

    醒目顯示的「Explorer」窗格按鈕。

  2. 在「Explorer」窗格中,點選「Connections」

  3. 在「Connections」(連線) 頁面中,按一下「Create connection」(建立連線)

  4. 在「外部資料來源」頁面中,執行下列操作:

    1. 在「連線類型」中,選擇「Vertex AI 遠端模型、遠端函式、Lakehouse 和 Spanner (Cloud 資源)」

    2. 在「連線 ID」欄位中輸入 cymbal_conn

    3. 其他設定維持不變,然後點按「建立連線」

  5. 在「連線」頁面中,按一下 cymbal_conn

  6. 在「連線資訊」窗格中,複製「服務帳戶 ID」值。後續步驟會用到這項資訊。

授予使用 Agent Platform 模型的權限

將 Agent Platform 使用者角色授予連線的服務帳戶,即可存取 Agent Platform 中的遠端模型。您必須在先前建立或選取的專案中授予這個角色。在其他專案中授予角色會導致錯誤 bqcx-1234567890-abcd@gcp-sa-bigquery-condel.iam.gserviceaccount.com does not have the permission to access resource

如要授予服務帳戶存取權,以便使用 Agent Platform 模型,請按照下列步驟操作:

  1. 前往「IAM & Admin」(IAM 與管理) 頁面。

    前往「IAM & Admin」(IAM 與管理)

  2. 按一下 「授予存取權」

  3. 在「授予存取權」對話方塊中,執行下列操作:

    1. 在「新增主體」欄位,輸入先前複製的服務帳戶 ID。

    2. 在「選取角色」欄位中,選擇或搜尋「Agent Platform 使用者」

    3. 按一下 [儲存]

建立 products 資料表

如要建立包含 Cymbal 寵物產品資訊的標準資料表,請按照下列步驟從 Cloud Storage 載入資料:

  1. 前往 Google Cloud 控制台的「Studio」頁面。

    前往 Studio

  2. 如要建立 products 資料表,請選擇下列任一選項:

    SQL

    將這個指令貼到查詢編輯器,然後按一下「執行」

    LOAD DATA OVERWRITE cymbal_pets.products
    FROM
      FILES(
        format = 'avro',
        uris = [
          'gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/tables/products/products_*.avro']);

    您會收到類似以下的確認訊息:Data was successfully loaded into managed table.

    BigQuery DataFrames

    在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

    如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

    import bigframes.bigquery as bbq
    import bigframes.pandas as bpd
    
    bbq.load_data(
        "cymbal_pets.products",
        write_disposition="OVERWRITE",
        from_files_options={
            "format": "avro",
            "uris": [
                "gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/tables/products/products_*.avro"
            ],
        },
    )
    import bigframes.bigquery as bbq
    import bigframes.pandas as bpd
    
    bbq.load_data(
        "cymbal_pets.products",
        write_disposition="OVERWRITE",
        from_files_options={
            "format": "avro",
            "uris": [
                "gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/tables/products/products_*.avro"
            ],
        },
    )

建立 product_images 資料表

如要建立包含 Cymbal 寵物產品圖片的物件表格 (product_images),請選取下列其中一個選項:



* { SQL }

  Paste this command into the query editor, and then click
  <span class="material-icons" aria-hidden="true">play_circle</span>
  **Run**:

  <pre class="lang-googlesql notranslate prettyprint devsite-click-to-copy">
  CREATE OR REPLACE EXTERNAL TABLE cymbal_pets.product_images
    WITH CONNECTION `us.cymbal_conn`
    OPTIONS (
      object_metadata = 'SIMPLE',
      uris = ['gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/images/*.png'],
      max_staleness = INTERVAL 30 MINUTE,
      metadata_cache_mode = AUTOMATIC);
  </pre>

  You receive a confirmation message similar to the following: `This
  statement created a new table named product_images.`

* { BigQuery DataFrames }

      

Before trying this sample, follow the BigQuery DataFrames setup instructions in the BigQuery quickstart using BigQuery DataFrames. For more information, see the BigQuery DataFrames reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up ADC for a local development environment.

bbq.create_external_table(
    "cymbal_pets.product_images",
    replace=True,
    connection_name="us.cymbal_conn",
    options={
        "object_metadata": "SIMPLE",
        "uris": [
            "gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/images/*.png"
        ],
    },
)
bbq.create_external_table(
    "cymbal_pets.product_images",
    replace=True,
    connection_name="us.cymbal_conn",
    options={
        "object_metadata": "SIMPLE",
        "uris": [
            "gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/images/*.png"
        ],
    },
)

可建立模型

本教學課程中的 SQL 指令會說明如何呼叫 AI 函式,不需要建立模型。如果您是按照 BigQuery DataFrames 指示操作,請選取這個選項,建立代表 Gemini 模型和多模態嵌入模型的遠端模型

SQL

你可以略過這個步驟。

BigQuery DataFrames

在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

gemini_model = bbq.ml.create_model(
    "cymbal_pets.gemini",
    replace=True,
    connection_name="us.cymbal_conn",
    options={"endpoint": "gemini-3.5-flash"},
)
gemini_model = bbq.ml.create_model(
    "cymbal_pets.gemini",
    replace=True,
    connection_name="us.cymbal_conn",
    options={"endpoint": "gemini-3.5-flash"},
)

embedding_model = bbq.ml.create_model(
    "cymbal_pets.embedding_model",
    replace=True,
    connection_name="us.cymbal_conn",
    options={"endpoint": "gemini-embedding-2"},
)
embedding_model = bbq.ml.create_model(
    "cymbal_pets.embedding_model",
    replace=True,
    connection_name="us.cymbal_conn",
    options={"endpoint": "gemini-embedding-2"},
)

建立包含多模態資料的 products_mm 資料表

建立 products_mm 資料表,其中包含從 product_images 物件資料表填入產品圖片的 image 資料欄。建立的 image 資料欄是 STRUCT 資料欄,會使用 ObjectRef 值,在 BigQuery 標準資料表中儲存圖片資料和結構化資料。

ObjectRef 值是具有預先定義結構定義的 STRUCT 型別,可參照用於多模態分析的 Cloud Storage 物件。 ObjectRef 值可由 OBJ 函式AI 函式Python 使用者定義函式處理。

如要建立及填入 products_mm 資料表,請按照下列步驟操作:

  1. 如要建立 products_mm 資料表,請選擇下列任一選項:

    SQL

    將這個指令貼到查詢編輯器,然後按一下「執行」

    CREATE OR REPLACE TABLE cymbal_pets.products_mm
    AS
    SELECT products.* EXCEPT (uri), ot.ref AS image FROM cymbal_pets.products
    INNER JOIN cymbal_pets.product_images ot
    ON ot.uri = products.uri;

    您會收到類似以下的確認訊息:This statement created a new table named products_mm.

    BigQuery DataFrames

    在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

    如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

    df_images = bpd.read_gbq("SELECT * FROM cymbal_pets.product_images")
    df_products = bpd.read_gbq("cymbal_pets.products")
    
    df_products_mm = df_images.merge(df_products, on="uri").drop(columns="uri")
    df_products_mm = df_products_mm.rename(columns={"ref": "image"})
    df_images = bpd.read_gbq("SELECT * FROM cymbal_pets.product_images")
    df_products = bpd.read_gbq("cymbal_pets.products")
    
    df_products_mm = df_images.merge(df_products, on="uri").drop(columns="uri")
    df_products_mm = df_products_mm.rename(columns={"ref": "image"})

  2. 如要查看 image 欄資料,請選擇下列任一選項:

    SQL

    將這個指令貼到查詢編輯器,然後按一下「執行」

    SELECT product_name, image
    FROM cymbal_pets.products_mm

    BigQuery DataFrames

    在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

    如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

    df_products_mm[["product_name", "image"]]
    df_products_mm[["product_name", "image"]]

    結果類似下方:

    +--------------------------------+--------------------------------------+---------------+-------------------------------+------------------------------------------------+
    | product_name                   | image.uri                            | image.version | image.authorizer              | image.details                                  |
    +--------------------------------+--------------------------------------+---------------+-------------------------------+------------------------------------------------+
    |  AquaClear Aquarium Background | gs://cloud-samples-data/bigquery/    | 1234567891011 | myproject.region.myconnection | {"gcs_metadata":{"content_type":"image/png",   |
    |                                | tutorials/cymbal-pets/images/        |               |                               | "md5_hash":"494f63b9b137975ff3e7a11b060edb1d", |
    |                                | aquaclear-aquarium-background.png    |               |                               | "size":1282805,"updated":1742492680017000}}    |
    +--------------------------------+--------------------------------------+---------------+-------------------------------+------------------------------------------------+
    |  AquaClear Aquarium            | gs://cloud-samples-data/bigquery/    | 2345678910112 | myproject.region.myconnection | {"gcs_metadata":{"content_type":"image/png",   |
    |  Gravel Vacuum                 | tutorials/cymbal-pets/images/        |               |                               | "md5_hash":"b7bfc2e2641a77a402a1937bcf0003fd", |
    |                                | aquaclear-aquarium-gravel-vacuum.png |               |                               | "size":820254,"updated":1742492682411000}}     |
    +--------------------------------+--------------------------------------+---------------+-------------------------------+------------------------------------------------+
    | ...                            | ...                                  | ...           |                               | ...                                            |
    +--------------------------------+--------------------------------------+---------------+-------------------------------+------------------------------------------------+
    

生成產品資訊

使用 AI.GENERATE 函式 為寵物商店產品產生下列資料:

  • products_mm 表格中新增 image_description 欄。
  • 填入 products_mm 資料表的 animal_typesearch_keywordssubcategory 欄。
  • 執行查詢,傳回每個產品品牌的說明,以及該品牌的產品數量。系統會分析該品牌所有產品的產品資訊 (包括產品圖片),然後生成品牌說明。

使用 AI.GENERATE 函式時,您可以選擇根據指定的自訂結構定義,生成文字或結構化輸出。這項函式會向 Gemini 模型傳送要求,並傳回包含生成資料、完整模型回應和狀態的結構體。

如要產生產品資料,請按照下列步驟操作:

  1. 如要使用 AI.GENERATE 生成產品資訊,請選擇下列任一選項:

    SQL

    如要建立及填入 image_description 欄,請將下列內容貼到查詢編輯器,然後按一下 「執行」

    -- Add the column to the existing table
    ALTER TABLE bqml_tutorial.products_mm
    ADD COLUMN IF NOT EXISTS image_description STRING;
    
    -- Populate the new column using the AI.GENERATE function
    UPDATE bqml_tutorial.products_mm
    SET image_description = AI.GENERATE(
    ('Describe the following image: ', image),
    endpoint => 'gemini-3.5-flash'
    ).result
    WHERE image_description IS NULL;

    您會收到類似以下的確認訊息:This statement altered the table named products_mm.

    BigQuery DataFrames

    在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

    如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

    df_products_mm["url"] = bbq.obj.get_access_url(
        df_products_mm["image"], "R"
    ).to_frame()
    df_products_mm["prompt0"] = "Can you describe the following image?"
    
    df_products_mm["prompt"] = bbq.struct(df_products_mm[["prompt0", "url"]])
    df_products_mm = bbq.ai.generate_table(
        gemini_model, df_products_mm, output_schema={"image_description": "STRING"}
    )
    
    df_products_mm = df_products_mm[
        [
            "product_id",
            "product_name",
            "brand",
            "category",
            "subcategory",
            "animal_type",
            "search_keywords",
            "price",
            "description",
            "inventory_level",
            "supplier_id",
            "average_rating",
            "image",
            "image_description",
        ]
    ]
    df_products_mm["url"] = bbq.obj.get_access_url(
        df_products_mm["image"], "R"
    ).to_frame()
    df_products_mm["prompt0"] = "Can you describe the following image?"
    
    df_products_mm["prompt"] = bbq.struct(df_products_mm[["prompt0", "url"]])
    df_products_mm = bbq.ai.generate_table(
        gemini_model, df_products_mm, output_schema={"image_description": "STRING"}
    )
    
    df_products_mm = df_products_mm[
        [
            "product_id",
            "product_name",
            "brand",
            "category",
            "subcategory",
            "animal_type",
            "search_keywords",
            "price",
            "description",
            "inventory_level",
            "supplier_id",
            "average_rating",
            "image",
            "image_description",
        ]
    ]

  2. 如要查看 image_description 資料欄的內容,請將下列內容貼到查詢編輯器,然後按一下 「執行」

    SELECT product_name, image_description
    FROM cymbal_pets.products_mm;

    結果類似下方:

    +--------------------------------+-------------------------------------+
    | product_name                   | image_description                   |
    +--------------------------------+-------------------------------------+
    |  AquaClear Aquarium Background | The image shows a colorful coral    |
    |                                | reef backdrop. The background is a  |
    |                                | blue ocean with a bright light...   |
    |                                |                                     |
    |                                |                                     |
    +--------------------------------+-------------------------------------+
    |  AquaClear Aquarium            | The image shows a long, clear       |
    |  Gravel Vacuum                 | plastic tube with a green hose      |
    |                                | attached to one end. The tube...    |
    |                                |                                     |
    |                                |                                     |
    +--------------------------------+-------------------------------------+
    | ...                            | ...                                 |
    +--------------------------------+-------------------------------------+
    
  3. 如要使用產生的資料更新「animal_type」、「search_keywords」和「subcategory」欄,請選擇下列其中一個選項:

    SQL

    將下列內容貼到查詢編輯器,然後點選「執行」

    UPDATE cymbal_pets.products_mm t
    SET
    animal_type = r.animal_type,
    search_keywords = SPLIT(r.search_keywords, ','),
    subcategory = r.subcategory
    FROM (
    SELECT
      product_id,
      g.* EXCEPT(full_response, status)
    FROM bqml_tutorial.products_mm,
    UNNEST([AI.GENERATE(
      ('For the image and description of a pet product, concisely generate the following metadata: 1) animal_type and 2) 5 SEO search keywords (comma separated), and 3) product subcategory. ', image, description),
      endpoint => 'gemini-3.5-flash',
      output_schema => 'animal_type STRING, search_keywords STRING, subcategory STRING'
    )]) AS g
    ) r
    WHERE t.product_id = r.product_id;

    您會收到類似以下的確認訊息:This statement modified 205 rows in products_mm.

    BigQuery DataFrames

    在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

    如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

    df_prompt = bbq.obj.get_access_url(df_products_mm["image"], "R").to_frame()
    df_prompt[
        "prompt0"
    ] = "For the image of a pet product, concisely generate the following metadata: 1) animal_type and 2) 5 SEO search keywords, and 3) product subcategory."
    
    df_products_mm["prompt"] = bbq.struct(df_prompt[["prompt0", "image"]])
    
    df_products_mm = df_products_mm.drop(
        columns=["animal_type", "search_keywords", "subcategory"]
    )
    df_products_mm = bbq.ai.generate_table(
        gemini_model,
        df_products_mm,
        output_schema="animal_type STRING, search_keywords ARRAY<STRING>, subcategory STRING",
    )
    df_prompt = bbq.obj.get_access_url(df_products_mm["image"], "R").to_frame()
    df_prompt[
        "prompt0"
    ] = "For the image of a pet product, concisely generate the following metadata: 1) animal_type and 2) 5 SEO search keywords, and 3) product subcategory."
    
    df_products_mm["prompt"] = bbq.struct(df_prompt[["prompt0", "image"]])
    
    df_products_mm = df_products_mm.drop(
        columns=["animal_type", "search_keywords", "subcategory"]
    )
    df_products_mm = bbq.ai.generate_table(
        gemini_model,
        df_products_mm,
        output_schema="animal_type STRING, search_keywords ARRAY<STRING>, subcategory STRING",
    )

  4. 如要查看產生的資料,請選擇下列其中一個選項:

    SQL

    將下列內容貼到查詢編輯器,然後點選「執行」

    SELECT
    product_name,
    image_description,
    animal_type,
    search_keywords,
    subcategory,
    FROM cymbal_pets.products_mm;

    BigQuery DataFrames

    在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

    如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

    df_products_mm[
        [
            "product_name",
            "image_description",
            "animal_type",
            "search_keywords",
            "subcategory",
        ]
    ]
    df_products_mm[
        [
            "product_name",
            "image_description",
            "animal_type",
            "search_keywords",
            "subcategory",
        ]
    ]

    結果類似下方:

    +--------------------------------+-------------------------------------+-------------+------------------------+------------------+
    | product_name                   | image_description                   | animal_type | search_keywords        | subcategory      |
    +--------------------------------+-------------------------------------+-------------+------------------------+------------------+
    |  AquaClear Aquarium Background | The image shows a colorful coral    | fish        | aquarium background    | aquarium decor   |
    |                                | reef backdrop. The background is a  |             | fish tank backdrop     |                  |
    |                                | blue ocean with a bright light...   |             | coral reef decor       |                  |
    |                                |                                     |             | underwater scenery     |                  |
    |                                |                                     |             | aquarium decoration    |                  |
    +--------------------------------+-------------------------------------+-------------+------------------------+------------------+
    |  AquaClear Aquarium            | The image shows a long, clear       | fish        | aquarium gravel vacuum | aquarium         |
    |  Gravel Vacuum                 | plastic tube with a green hose      |             | aquarium cleaning      | cleaning         |
    |                                | attached to one end. The tube...    |             | aquarium maintenance   |                  |
    |                                |                                     |             | fish tank cleaning     |                  |
    |                                |                                     |             | gravel siphon          |                  |
    +--------------------------------+-------------------------------------+-------------+------------------------+------------------+
    | ...                            | ...                                 | ...         |  ...                   | ...              |
    +--------------------------------+-------------------------------------+-------------+------------------------+------------------+
    
  5. 如要產生每個產品品牌的說明,以及該品牌產品的數量,請選擇下列其中一個選項:

    SQL

    將下列內容貼到查詢編輯器,然後點選「執行」

    SELECT
    brand,
    COUNT(*) AS cnt,
    AI.GENERATE(('Use the images and text to give one concise brand description ',
                'for a website brand page. Return the description only.',
                  ARRAY_AGG(image LIMIT 10), ARRAY_AGG(description), ARRAY_AGG(category),
                  ARRAY_AGG(subcategory)),
                endpoint => 'gemini-2.5-pro').result AS brand_description
    FROM
    cymbal_pets.products_mm
    GROUP BY brand
    ORDER BY cnt DESC;

    BigQuery DataFrames

    在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

    如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

    df_agg = df_products_mm[
        ["image", "description", "category", "subcategory", "brand"]
    ]
    df_agg["image"] = bbq.obj.get_access_url(df_products_mm["image"], "R")
    df_agg = bbq.array_agg(df_agg.groupby(by=["brand"]))
    
    df_agg["cnt"] = bbq.array_length(df_agg["image"])
    
    df_prompt = df_agg[["image", "description", "category", "subcategory"]]
    df_prompt[
        "prompt0"
    ] = "Use the images and text to give one concise brand description for a website brand page. Return the description only. "
    
    df_agg["prompt"] = bbq.struct(
        df_prompt[["prompt0", "image", "description", "category", "subcategory"]]
    )
    
    df_agg = df_agg.reset_index()
    
    df_agg = bbq.ai.generate_table(
        gemini_model, df_agg, output_schema={"brand_description": "STRING"}
    )
    df_agg[["brand", "brand_description", "cnt"]]
    df_agg = df_products_mm[
        ["image", "description", "category", "subcategory", "brand"]
    ]
    df_agg["image"] = bbq.obj.get_access_url(df_products_mm["image"], "R")
    df_agg = bbq.array_agg(df_agg.groupby(by=["brand"]))
    
    df_agg["cnt"] = bbq.array_length(df_agg["image"])
    
    df_prompt = df_agg[["image", "description", "category", "subcategory"]]
    df_prompt[
        "prompt0"
    ] = "Use the images and text to give one concise brand description for a website brand page. Return the description only. "
    
    df_agg["prompt"] = bbq.struct(
        df_prompt[["prompt0", "image", "description", "category", "subcategory"]]
    )
    
    df_agg = df_agg.reset_index()
    
    df_agg = bbq.ai.generate_table(
        gemini_model, df_agg, output_schema={"brand_description": "STRING"}
    )
    df_agg[["brand", "brand_description", "cnt"]]

    結果類似下方:

    +--------------+-------------------------------------+-----+
    | brand        | brand_description                   | cnt |
    +--------------+-------------------------------------+-----+
    |  AquaClear   | AquaClear is a brand of aquarium    | 33  |
    |              | and pond care products that offer   |     |
    |              | a wide range of solutions for...    |     |
    +--------------+-------------------------------------+-----+
    |  Ocean       | Ocean Bites is a brand of cat food  | 28  |
    |  Bites       | that offers a variety of recipes    |     |
    |              | and formulas to meet the specific.. |     |
    +--------------+-------------------------------------+-----+
    |  ...         | ...                                 |...  |
    +--------------+-------------------------------------+-----+
    

從圖片資料生成嵌入項目,然後使用嵌入項目透過向量搜尋傳回類似圖片。

在正式環境中,建議您先建立向量索引,再執行向量搜尋。向量索引可加快向量搜尋速度,並傳回更近似的結果,但召回率會降低。

如要建立嵌入內容並執行向量搜尋,請按照下列步驟操作:

  1. 如要建立 products_embeddings 資料表,請選擇下列其中一個選項:

    SQL

    將下列內容貼到查詢編輯器,然後點選「執行」

    CREATE OR REPLACE TABLE cymbal_pets.products_embedding
    AS (
    SELECT
      product_id,
      AI.EMBED(image, endpoint => 'gemini-embedding-2').result AS embedding,
      image
    FROM cymbal_pets.products_mm
    );

    您會收到類似以下的確認訊息:This statement created a new table named products_embedding.

    BigQuery DataFrames

    在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

    如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

    df_products_mm["content"] = bbq.obj.get_access_url(df_products_mm["image"], "R")
    df_embed = bbq.ai.generate_embedding(
        embedding_model, df_products_mm[["content", "product_id"]]
    )
    
    df_embed.to_gbq("cymbal_pets.products_embedding", if_exists="replace")
    df_products_mm["content"] = bbq.obj.get_access_url(df_products_mm["image"], "R")
    df_embed = bbq.ai.generate_embedding(
        embedding_model, df_products_mm[["content", "product_id"]]
    )
    
    df_embed.to_gbq("cymbal_pets.products_embedding", if_exists="replace")

  2. 如要執行向量搜尋,傳回與指定輸入圖片相似的產品圖片,請選擇下列任一選項:

    SQL

    將下列內容貼到查詢編輯器,然後點選「執行」

    SELECT *
    FROM
    VECTOR_SEARCH(
      TABLE cymbal_pets.products_embedding,
      'embedding',
      query_value => AI.EMBED(
                      OBJ.MAKE_REF('gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/images/cozy-naps-cat-scratching-post-with-condo.png'),
                      endpoint => 'gemini-embedding-2').result);

    BigQuery DataFrames

    在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

    如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

    df_image = bpd.DataFrame(
        {
            "uri": [
                "gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/images/cozy-naps-cat-scratching-post-with-condo.png"
            ]
        }
    ).cache()
    df_image["image"] = bbq.obj.make_ref(df_image["uri"], "us.cymbal_conn")
    df_search = bbq.ai.generate_embedding(
        embedding_model,
        bbq.obj.get_access_url(bbq.obj.fetch_metadata(df_image["image"]), "R"),
    )
    
    search_result = bbq.vector_search(
        "cymbal_pets.products_embedding", "embedding", df_search["embedding"]
    )
    search_result
    df_image = bpd.DataFrame(
        {
            "uri": [
                "gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/images/cozy-naps-cat-scratching-post-with-condo.png"
            ]
        }
    ).cache()
    df_image["image"] = bbq.obj.make_ref(df_image["uri"], "us.cymbal_conn")
    df_search = bbq.ai.generate_embedding(
        embedding_model,
        bbq.obj.get_access_url(bbq.obj.fetch_metadata(df_image["image"]), "R"),
    )
    
    search_result = bbq.vector_search(
        "cymbal_pets.products_embedding", "embedding", df_search["embedding"]
    )
    search_result

    結果類似下方:

    +-----------------+-----------------+----------------+----------------------------------------------+--------------------+-------------------------------+------------------------------------------------+----------------+
    | query.embedding | base.product_id | base.embedding | base.image.uri                               | base.image.version | base.image.authorizer         | base.image.details                             | distance       |
    +-----------------+-----------------+----------------+----------------------------------------------+--------------------+-------------------------------+------------------------------------------------+----------------+
    | -0.0112330541   | 181             | -0.0112330541  | gs://cloud-samples-data/bigquery/            | 12345678910        | myproject.region.myconnection | {"gcs_metadata":{"content_type":               | 0.0            |
    | 0.0142525584    |                 |  0.0142525584  | tutorials/cymbal-pets/images/                |                    |                               | "image/png","md5_hash":"21234567hst16555w60j", |                |
    | 0.0135886827    |                 |  0.0135886827  | cozy-naps-cat-scratching-post-with-condo.png |                    |                               | "size":828318,"updated":1742492688982000}}     |                |
    | 0.0149955815    |                 |  0.0149955815  |                                              |                    |                               |                                                |                |
    | ...             |                 |  ...           |                                              |                    |                               |                                                |                |
    |                 |                 |                |                                              |                    |                               |                                                |                |
    |                 |                 |                |                                              |                    |                               |                                                |                |
    +-----------------+-----------------+----------------+----------------------------------------------+--------------------+-------------------------------+------------------------------------------------+----------------+
    | -0.0112330541   | 187             | -0.0190353896  | gs://cloud-samples-data/bigquery/            | 23456789101        | myproject.region.myconnection | {"gcs_metadata":{"content_type":               | 0.4216330832.. |
    | 0.0142525584    |                 |  0.0116206668  | tutorials/cymbal-pets/images/                |                    |                               | "image/png","md5_hash":"7328728fhakd9937djo4", |                |
    | 0.0135886827    |                 |  0.0136198215  | cozy-naps-cat-scratching-post-with-bed.png   |                    |                               | "size":860113,"updated":1742492688774000}}     |                |
    | 0.0149955815    |                 |  0.0173457414  |                                              |                    |                               |                                                |                |
    | ...             |                 |  ...           |                                              |                    |                               |                                                |                |
    |                 |                 |                |                                              |                    |                               |                                                |                |
    |                 |                 |                |                                              |                    |                               |                                                |                |
    +-----------------+-----------------+----------------+----------------------------------------------+--------------------+-------------------------------+------------------------------------------------+----------------+
    | ...             | ...             | ...            | ...                                          | ...                | ...                           | ...                                            | ...            |
    +-----------------+-----------------+----------------+----------------------------------------------+--------------------+-------------------------------+------------------------------------------------+----------------+
    

使用 ObjectRef 值陣列處理排序的多模態資料

本節說明如何使用 ObjectRef 值陣列處理排序的多模態資料,藉此摘要使用者手冊內容。BigQuery 可使用陣列同時分析多個非結構化檔案。

您將完成下列工作:

  1. 建立 product_manuals 表格,其中包含 Crittercuisine Pro 5000 產品手冊的 PDF 檔案,以及該手冊每一頁的 PDF 檔案。

  2. 建立表格,將手冊對應至各個區塊。完整手冊和手冊頁面分別儲存在 ObjectRef 欄中。

  3. 一起分析 ObjectRef 值陣列,傳回單一生成值。

  4. 分別分析 ObjectRef 值陣列,並為每個陣列值傳回產生的值。

如要使用 ObjectRef 值處理排序的多模態資料,請按照下列步驟操作:

  1. 如要建立 product_manuals 資料表,請選擇下列任一選項:

    SQL

    將下列內容貼到查詢編輯器,然後點選「執行」

    CREATE OR REPLACE EXTERNAL TABLE `cymbal_pets.product_manuals`
    WITH CONNECTION `us.cymbal_conn`
    OPTIONS (
      object_metadata = 'SIMPLE',
      uris = [
          'gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/documents/*.pdf',
          'gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/document_chunks/*.pdf']);

    您會收到類似以下的確認訊息:This statement created a new table named product_manuals.

    BigQuery DataFrames

    在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

    如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

    bbq.create_external_table(
        "cymbal_pets.product_manuals_all",
        replace=True,
        connection_name="us.cymbal_conn",
        options={
            "object_metadata": "SIMPLE",
            "uris": [
                "gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/documents/*.pdf",
                "gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/document_chunks/*.pdf",
            ],
        },
    )
    bbq.create_external_table(
        "cymbal_pets.product_manuals_all",
        replace=True,
        connection_name="us.cymbal_conn",
        options={
            "object_metadata": "SIMPLE",
            "uris": [
                "gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/documents/*.pdf",
                "gs://cloud-samples-data/bigquery/tutorials/cymbal-pets/document_chunks/*.pdf",
            ],
        },
    )

  2. 如要將 PDF 資料寫入 map_manual_to_chunks 資料表,請選擇下列其中一個選項:

    SQL

    將下列內容貼到查詢編輯器,然後點選「執行」

    -- Extract the file and chunks into a single table.
    -- Store the chunks in the chunks column as array of ObjectRefs (ordered by page number)
    CREATE OR REPLACE TABLE cymbal_pets.map_manual_to_chunks
    AS
    SELECT ARRAY_AGG(m1.ref)[0] manual, ARRAY_AGG(m2.ref ORDER BY m2.ref.uri) chunks
    FROM cymbal_pets.product_manuals m1
    JOIN cymbal_pets.product_manuals m2
    ON
      REGEXP_EXTRACT(m1.uri, r'.*/([^.]*).[^/]+')
      = REGEXP_EXTRACT(m2.uri, r'.*/([^.]*)_page[0-9]+.[^/]+')
    GROUP BY m1.uri;

    您會收到類似以下的確認訊息:This statement created a new table named map_manual_to_chunks.

    BigQuery DataFrames

    在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

    如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

    df1 = bpd.read_gbq("SELECT * FROM cymbal_pets.product_manuals_all").sort_values(
        "uri"
    )
    df2 = df1.copy()
    df1["name"] = df1["uri"].str.extract(r".*/([^.]*).[^/]+")
    df2["name"] = df2["uri"].str.extract(r".*/([^.]*)_page[0-9]+.[^/]+")
    df_manuals_all = df1.merge(df2, on="name")
    df_manuals_agg = (
        bbq.array_agg(df_manuals_all[["ref_x", "uri_x"]].groupby("uri_x"))["ref_x"]
        .str[0]
        .to_frame()
    )
    df_manuals_agg["chunks"] = bbq.array_agg(
        df_manuals_all[["ref_y", "uri_x"]].groupby("uri_x")
    )["ref_y"]
    df1 = bpd.read_gbq("SELECT * FROM cymbal_pets.product_manuals_all").sort_values(
        "uri"
    )
    df2 = df1.copy()
    df1["name"] = df1["uri"].str.extract(r".*/([^.]*).[^/]+")
    df2["name"] = df2["uri"].str.extract(r".*/([^.]*)_page[0-9]+.[^/]+")
    df_manuals_all = df1.merge(df2, on="name")
    df_manuals_agg = (
        bbq.array_agg(df_manuals_all[["ref_x", "uri_x"]].groupby("uri_x"))["ref_x"]
        .str[0]
        .to_frame()
    )
    df_manuals_agg["chunks"] = bbq.array_agg(
        df_manuals_all[["ref_y", "uri_x"]].groupby("uri_x")
    )["ref_y"]

  3. 如要在 map_manual_to_chunks 表格中查看 PDF 資料,請選擇下列其中一個選項:

    SQL

    將下列內容貼到查詢編輯器,然後點選「執行」

    SELECT *
    FROM cymbal_pets.map_manual_to_chunks;

    BigQuery DataFrames

    在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

    如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

    df_manuals_agg
    df_manuals_agg

    結果類似下方:

    +-------------------------------------+--------------------------------+-----------------------------------+------------------------------------------------------+-------------------------------------------+---------------------------------+------------------------------------+-------------------------------------------------------+
    | manual.uri                          | manual.version                 | manual.authorizer                 | manual.details                                       | chunks.uri                                | chunks.version                  | chunks.authorizer                  | chunks.details                                        |
    +-------------------------------------+--------------------------------+-----------------------------------+------------------------------------------------------+-------------------------------------------+---------------------------------+------------------------------------+-------------------------------------------------------+
    | gs://cloud-samples-data/bigquery/   | 1742492785900455               | myproject.region.myconnection     | {"gcs_metadata":{"content_type":"application/pef",   | gs://cloud-samples-data/bigquery/         | 1745875761227129                | myproject.region.myconnection      | {"gcs_metadata":{"content_type":"application/pdf",    |
    | tutorials/cymbal-pets/documents/    |                                |                                   | "md5_hash":"c9032b037693d15a33210d638c763d0e",       | tutorials/cymbal-pets/documents/          |                                 |                                    | "md5_hash":"5a1116cce4978ec1b094d8e8b49a1d7c",        |
    | crittercuisine_5000_user_manual.pdf |                                |                                   | "size":566105,"updated":1742492785941000}}           | crittercuisine_5000_user_manual_page1.pdf |                                 |                                    | "size":504583,"updated":1745875761266000}}            |
    |                                     |                                |                                   |                                                      +-------------------------------------------+---------------------------------+------------------------------------+-------------------------------------------------------+
    |                                     |                                |                                   |                                                      | crittercuisine_5000_user_manual_page1.pdf | 1745875760613874                | myproject.region.myconnection      | {"gcs_metadata":{"content_type":"application/pdf",    |
    |                                     |                                |                                   |                                                      | tutorials/cymbal-pets/documents/          |                                 |                                    | "md5_hash":"94d03ec65d28b173bc87eac7e587b325",        |
    |                                     |                                |                                   |                                                      | crittercuisine_5000_user_manual_page2.pdf |                                 |                                    | "size":94622,"updated":1745875760649000}}             |
    |                                     |                                |                                   |                                                      +-------------------------------------------+---------------------------------+------------------------------------+-------------------------------------------------------+
    |                                     |                                |                                   |                                                      | ...                                       | ...                             |  ...                               | ...                                                   |
    +-------------------------------------+--------------------------------+-----------------------------------+------------------------------------------------------+-------------------------------------------+---------------------------------+------------------------------------+-------------------------------------------------------+
    
  4. 如要根據 ObjectRef 值陣列的分析結果,從 Gemini 模型生成單一回覆,請選擇下列其中一個選項:

    SQL

    將下列內容貼到查詢編輯器,然後點選「執行」

    SELECT
    AI.GENERATE((
      '''Can you provide a page by page summary for the first 3 pages of the attached manual?
      Only write one line for each page. The pages are provided in serial order''',
      chunks),
      endpoint => 'gemini-3.5-flash').result AS Response,
    FROM cymbal_pets.map_manual_to_chunks;

    BigQuery DataFrames

    在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

    如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

    df_manuals_agg["chunks_url"] = bbq.array_agg(
        bbq.obj.get_access_url(df_manuals_agg.explode("chunks")["chunks"], "R").groupby(
            "uri_x"
        )
    )
    df_manuals_agg[
        "prompt0"
    ] = "Can you provide a page by page summary for the first 3 pages of the attached manual? Only write one line for each page. The pages are provided in serial order"
    df_manuals_agg["prompt"] = bbq.struct(df_manuals_agg[["prompt0", "chunks_url"]])
    
    result = bbq.ai.generate_text(gemini_model, df_manuals_agg["prompt"])["result"]
    result
    df_manuals_agg["chunks_url"] = bbq.array_agg(
        bbq.obj.get_access_url(df_manuals_agg.explode("chunks")["chunks"], "R").groupby(
            "uri_x"
        )
    )
    df_manuals_agg[
        "prompt0"
    ] = "Can you provide a page by page summary for the first 3 pages of the attached manual? Only write one line for each page. The pages are provided in serial order"
    df_manuals_agg["prompt"] = bbq.struct(df_manuals_agg[["prompt0", "chunks_url"]])
    
    result = bbq.ai.generate_text(gemini_model, df_manuals_agg["prompt"])["result"]
    result

    結果類似下方:

    +---------------------------------------------------------------------------+
    | Response                                                                  |
    +---------------------------------------------------------------------------+
    | Here is a one-line summary for each of the first 3 pages:                 |
    |                                                                           |
    | Page 1 introduces the CritterCuisine Pro 5000 automatic pet feeder and    |
    | presents the initial part of the manual's Table of Contents.              |
    | Page 2 lists the items included with the feeder and details important     |
    | safety precautions for its use.                                           |
    | Page 3 describes the feeder's key features, provides assembly and initial |
    | setup instructions, and begins the programming guide with clock setting.  |
    +---------------------------------------------------------------------------+
    
  5. 如要根據陣列的 ObjectRef 值分析結果,讓 Gemini 模型生成多個回覆,請選擇下列其中一個選項:

    SQL

    將下列內容貼到查詢編輯器,然後點選「執行」

    WITH results AS (
    SELECT
      AI.GENERATE((
        '''Can you provide a page by page summary for the first 3 pages of the attached manual?
        Only write one line for each page. The pages are provided in serial order''',
        chunks),
        endpoint => 'gemini-3.5-flash',
        output_schema =>  'page1_summary STRING, page2_summary STRING, page3_summary STRING').*
    FROM cymbal_pets.map_manual_to_chunks)
    SELECT page1_summary, page2_summary, page3_summary
    FROM results;

    BigQuery DataFrames

    在嘗試這個範例之前,請按照使用 BigQuery DataFrames 的 BigQuery 快速入門導覽課程,完成 BigQuery DataFrames 設定。詳情請參閱 BigQuery DataFrames 參考文件

    如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定 ADC」。

    result = bbq.ai.generate_table(
        gemini_model,
        df_manuals_agg["prompt"],
        output_schema={
            "page1_summary": "STRING",
            "page2_summary": "STRING",
            "page3_summary": "STRING",
        },
    )[["page1_summary", "page2_summary", "page3_summary"]]
    result
    result = bbq.ai.generate_table(
        gemini_model,
        df_manuals_agg["prompt"],
        output_schema={
            "page1_summary": "STRING",
            "page2_summary": "STRING",
            "page3_summary": "STRING",
        },
    )[["page1_summary", "page2_summary", "page3_summary"]]
    result

    結果類似下方:

    +-----------------------------------------------+-------------------------------------------+----------------------------------------------------+
    | page1_summary                                 | page2_summary                             | page3_summary                                      |
    +-----------------------------------------------+-------------------------------------------+----------------------------------------------------+
    | This manual provides an overview of the       | This section explains how to program      | This page covers connecting the feeder to Wi-Fi    |
    | CritterCuisine Pro 5000 automatic pet feeder, | the feeder's clock, set feeding           | using the CritterCuisine Connect app,  remote      |
    | including its features, safety precautions,   | schedules, copy and delete meal settings, | feeding, managing feeding schedules, viewing       |
    | assembly instructions, and initial setup.     | manually feed your pet, record            | feeding logs, receiving low food alerts,           |
    |                                               | a voice message, and understand           | updating firmware, creating multiple pet profiles, |
    |                                               | the low food level indicator.             | sharing access with other users, and cleaning      |
    |                                               |                                           | and maintaining the feeder.                        |
    +-----------------------------------------------+-------------------------------------------+----------------------------------------------------+
    

清除所用資源

為避免因為本教學課程所用資源,導致系統向 Google Cloud 帳戶收取費用,請刪除含有相關資源的專案,或者保留專案但刪除個別資源。

  1. 前往 Google Cloud 控制台的「Manage resources」(管理資源) 頁面。

    前往「Manage resources」(管理資源)

  2. 在專案清單中選取要刪除的專案,然後點選「Delete」(刪除)
  3. 在對話方塊中輸入專案 ID,然後按一下 [Shut down] (關閉) 以刪除專案。

如要保留專案,但刪除本教學課程中使用的資源,請按照下列步驟操作:

  1. 前往「BigQuery」頁面

    前往「BigQuery」

  2. 在左側窗格中展開專案,然後按一下「資料集」

  3. 針對 bqml_tutorial 資料集,依序點按 「Open actions」(開啟動作) >「Delete」(刪除)

  4. 在「Delete dataset」(刪除資料集) 對話方塊中,按一下「Delete」(刪除) 進行確認。

  5. 按一下左側窗格中的「連線」

  6. 如要刪除 cymbal_conn 連結,請依序點按 「開啟動作」> 刪除

  7. 在「Delete connection」(刪除連結) 對話方塊中輸入 delete,然後按一下「Delete」(刪除) 確認操作。

後續步驟