調整文字嵌入

本頁說明如何調整文字嵌入模型。

基礎嵌入模型是以大量文字資料集預先訓練而成,可為許多工作提供強大的基準。如果需要專業知識或高度客製化的效能,您可以使用自己的相關資料微調模型表示法。下列文字嵌入模型支援調整:

按一下即可展開支援的模型

  • text-embedding-004
  • text-embedding-005
  • text-multilingual-embedding-002

文字嵌入模型支援監督式調整。監督式調整會使用有標籤樣本,示範您希望文字嵌入模型在推論期間輸出的內容類型。

如要進一步瞭解模型調整,請參閱「模型調整的運作方式」。

預期品質提升

Gemini Enterprise Agent Platform 採用參數高效微調方法進行自訂。在公開檢索基準資料集上進行的實驗中,這種方法可大幅提升品質,最高可達 41% (平均 12%)。

調整嵌入模型的用途

調整文字嵌入模型,可讓模型適應特定領域或任務的嵌入。如果預先訓練的嵌入模型不符合您的特定需求,這個方法就很有用。舉例來說,您可以使用公司客服單的特定資料集,微調嵌入模型。這有助於聊天機器人瞭解客戶通常會遇到的各種客服問題,並更有效地回答問題。如果未經調整,模型就不會知道客戶支援單的具體內容,或產品特定問題的解決方案。

調整工作流程

Gemini Enterprise Agent Platform 的模型調整工作流程如下:

  • 準備模型調整資料集。
  • 將模型調整資料集上傳至 Cloud Storage bucket。
  • 設定 Gemini Enterprise Agent Platform Pipelines 專案。
  • 建立模型調整工作。
  • 將調整後的模型部署至同名的 Gemini Enterprise Agent Platform 端點。與文字模型調整工作不同,文字嵌入調整工作不會將調整後的模型部署至 Gemini Enterprise Agent Platform 端點。

準備嵌入資料集

用於調整嵌入模型的資料集,包含與您希望模型執行的工作相符的資料。

調整嵌入模型時使用的資料集格式

訓練資料集包含下列檔案,這些檔案必須位於 Cloud Storage。啟動調整管道時,檔案路徑會由參數定義。這三種檔案分別是語料庫檔案、查詢檔案和標籤。您只需要提供訓練標籤,但也可以提供驗證和測試標籤,進一步控管。

  • 語料庫檔案:路徑由參數 corpus_path 定義。這是一個 JSONL 檔案,每行都有 _id、title 和 text 欄位,且含有字串值。_id 和 text 為必要欄位,title 則為選用欄位。以下是 corpus.jsonl 檔案範例:

    {"_id": "doc1", "title": "Get an introduction to Agent Platform", "text": "Agent Studio offers a Google Cloud console tool for rapidly prototyping and testing generative AI models. Learn how you can use Agent Studio to test models using prompt samples, design and save prompts, tune a foundation model, and convert between speech and text."}
    {"_id": "doc2", "title": "Use gen AI for summarization, classification, and extraction", "text": "Learn how to create text prompts for handling any number of tasks with Agent Platform's generative AI support. Some of the most common tasks are classification, summarization, and extraction. Agent Platform's PaLM API for text lets you design prompts with flexibility in terms of their structure and format."}
    {"_id": "doc3", "title": "Custom ML training overview and documentation", "text": "Get an overview of the custom training workflow in Agent Platform, the benefits of custom training, and the various training options that are available. This page also details every step involved in the ML training workflow from preparing data to inferences."}
    {"_id": "doc4", "text": "Text embeddings are useful for clustering, information retrieval, retrieval-augmented generation (RAG), and more."}
    {"_id": "doc5", "title": "Text embedding tuning", "text": "Google's text embedding models can be tuned on Agent Platform."}
    
  • 查詢檔案:查詢檔案包含查詢範例。路徑由 queries_path 參數定義。查詢檔案採用 JSONL 格式,欄位與語料庫檔案相同。以下是 queries.jsonl 檔案範例:

    {"_id": "query1", "text": "Does Vertex support generative AI?"}
    {"_id": "query2", "text": "What can I do with Vertex GenAI offerings?"}
    {"_id": "query3", "text": "How do I train my models using Vertex?"}
    {"_id": "query4", "text": "What is a text embedding?"}
    {"_id": "query5", "text": "Can text embedding models be tuned on Vertex?"}
    {"_id": "query6", "text": "embeddings"}
    {"_id": "query7", "text": "embeddings for rag"}
    {"_id": "query8", "text": "custom model training"}
    {"_id": "query9", "text": "Google Cloud PaLM API"}
    
  • 訓練標籤:路徑由 train_label_path 參數定義。train_label_path 是訓練標籤資料位置的 Cloud Storage URI,會在建立調整工作時指定。標籤必須是含有標頭的 TSV 檔案。訓練標籤檔案中必須包含部分查詢和語料庫。檔案必須包含 query-id、corpus-id 和 score 欄。query-id 是與查詢檔案中的 _id 鍵相符的字串,corpus-id 是與語料庫檔案中的 _id 相符的字串。Score 是非負整數值。如果查詢和文件不相關,您可以不將其納入訓練標籤檔案,或將其分數設為零。只要分數大於零,就表示文件與查詢相關。數字越大,表示關聯性越高。如果省略分數,預設值為 1。以下是 train_labels.tsv 檔案範例:

    query-id  corpus-id   score
    query1    doc1    1
    query2    doc2    1
    query3    doc3    2
    query3    doc5  1
    query4    doc4  1
    query4    doc5  1
    query5    doc5  2
    query6    doc4  1
    query6    doc5  1
    query7    doc4  1
    query8    doc3  1
    query9    doc2  1
    
  • 測試標籤:選用。測試標籤的格式與訓練標籤相同,並由 test_label_path 參數指定。如未提供 test_label_path,系統會自動從訓練標籤中分割測試標籤。

  • 驗證標籤:選用。驗證標籤的格式與訓練標籤相同,並由 validation_label_path 參數指定。如未提供 validation_label_path,系統會自動從訓練標籤分割驗證標籤。

資料集大小規定

提供的資料集檔案必須符合下列限制:

  • 查詢數量必須介於 9 到 10,000 之間。
  • 語料庫中的文件數量必須介於 9 到 500,000 之間。
  • 每個資料集標籤檔案必須包含至少 3 個查詢 ID,且所有資料集分割中必須至少有 9 個查詢 ID。
  • 標籤總數必須少於 500,000 個。

設定 Gemini Enterprise Agent Platform Pipelines 專案

調整作業會在專案中使用 Gemini Enterprise Agent Platform Pipelines 平台執行。

設定權限

管道會透過兩個服務代理執行訓練程式碼。您必須為這些服務代理程式授予特定角色,才能使用專案和資料集開始訓練。

Compute Engine 預設服務帳戶
PROJECT_NUMBER-compute@developer.gserviceaccount.com

這個服務帳戶需要:

  • Storage Object Viewer您在 Cloud Storage 建立的每個資料集檔案。
  • Storage Object User 存取管道的輸出 Cloud Storage 目錄 PIPELINE_OUTPUT_DIRECTORY。
  • Agent Platform User專案存取權。

您可以指定自訂服務帳戶,而非 Compute Engine 預設服務帳戶。詳情請參閱「設定具有精細權限的服務帳戶」。

Gemini Enterprise Agent Platform Tuning Service Agent
service-PROJECT_NUMBER@gcp-sa-aiplatform-ft.iam.gserviceaccount.com

這個服務帳戶需要:

  • Storage Object Viewer您在 Cloud Storage 建立的每個資料集檔案。
  • Storage Object User 存取管道的輸出 Cloud Storage 目錄 PIPELINE_OUTPUT_DIRECTORY。

如要進一步瞭解如何設定 Cloud Storage 資料集權限,請參閱「為管道構件設定 Cloud Storage bucket」。

使用加速器

微調作業需要 GPU 加速器。下列任一加速器都可用於文字嵌入調整管道:

  • NVIDIA_L4
  • NVIDIA_TESLA_A100
  • NVIDIA_TESLA_T4
  • NVIDIA_TESLA_V100
  • NVIDIA_TESLA_P100

如要啟動調整工作,您選取的加速器類型和區域必須有足夠的 Restricted image training GPUs 配額,例如 Restricted image training Nvidia V100 GPUs per region。如要提高專案配額,請參閱「申請更多配額」一節。

部分加速器僅在特定區域提供。詳情請參閱「在 Gemini Enterprise Agent Platform 中使用加速器」。

建立嵌入模型調整工作

您可以使用 Google Cloud 控制台、REST API 或用戶端程式庫,建立嵌入模型調整工作。

REST

如要建立嵌入模型微調工作,請使用 projects.locations.pipelineJobs.create 方法。

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID: Google Cloud 專案 ID。
  • PIPELINE_OUTPUT_DIRECTORY:管道輸出構件的路徑,開頭為「gs://」。

HTTP 方法和網址:

POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/pipelineJobs

JSON 要求主體:

{
  "displayName": "tune_text_embeddings_model_sample",
  "runtimeConfig": {
    "gcsOutputDirectory": "PIPELINE_OUTPUT_DIRECTORY",
    "parameterValues": {
      "corpus_path": "gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/corpus.jsonl",
      "queries_path": "gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/queries.jsonl",
      "train_label_path": "gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/train.tsv",
      "test_label_path": "gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/test.tsv",
      "base_model_version_id":"text-embedding-004",
      "task_type": "DEFAULT",
      "batch_size": "128",
      "train_steps": "1000",
      "output_dimensionality": "768",
      "learning_rate_multiplier": "1.0"
    }
  },
  "templateUri": "https://us-kfp.pkg.dev/ml-pipeline/llm-text-embedding/tune-text-embedding-model/v1.1.3"
}

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

啟動 pipeline 後,請透過 Google Cloud 控制台追蹤調整工作的進度。

前往 Google Cloud 控制台

Python

在試用這個範例之前,請先按照「使用用戶端程式庫的 Agent Platform 快速入門導覽課程」中的 Python 設定說明操作。

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

import os

from google.cloud import aiplatform

# TODO (Developer) set the following environment variables.
PROJECT_ID = os.getenv("PROJECT_ID")
LOCATION_ID = os.getenv("LOCATION_ID", "us-central1")
MODEL_NAME = os.getenv("MODEL_NAME", "text-embedding-004")
# A storage bucket: gs://your-bucket-name/embedding-tuning-output
OUTPUT_URI = os.getenv("OUTPUT_DIR")

TRAIN_LABEL_PATH = (
    "gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/train.tsv"
)
TEST_LABEL_PATH = (
    "gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/test.tsv"
)
CORPUS_PATH = (
    "gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/corpus.jsonl"
)
QUERIES_PATH = (
    "gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/queries.jsonl"
)

ACCELERATOR_TYPE = "NVIDIA_L4"

# Official Google Cloud KFP pipeline template URI for text embedding model tuning
EMBEDDING_TUNING_PIPELINE_URI = "https://us-kfp.pkg.dev/ml-pipeline/llm-text-embedding/tune-text-embedding-model/v1.1.3"


def tune_embedding_model() -> aiplatform.PipelineJob:
    """Tune an embedding model using the specified parameters."""

    aiplatform.init(project=PROJECT_ID, location=LOCATION_ID)

    # Configure parameters expected by the embedding tuning pipeline template
    pipeline_parameters = {
        "base_model_version_id": MODEL_NAME,
        "corpus_path": CORPUS_PATH,
        "queries_path": QUERIES_PATH,
        "train_label_path": TRAIN_LABEL_PATH,
        "test_label_path": TEST_LABEL_PATH,
        "accelerator_type": ACCELERATOR_TYPE,
    }

    # Instantiate the Vertex AI Pipeline job
    pipeline_job = aiplatform.PipelineJob(
        display_name="tune-text-embedding-model-job",
        template_path=EMBEDDING_TUNING_PIPELINE_URI,
        pipeline_root=OUTPUT_URI,
        parameter_values=pipeline_parameters,
        project=PROJECT_ID,
        location=LOCATION_ID,
    )

    pipeline_job.submit()

    print(f"Pipeline submitted successfully: {pipeline_job.resource_name}")

    return pipeline_job

Java

在試用這個範例之前,請先按照「使用用戶端程式庫的 Agent Platform 快速入門導覽課程」中的 Java 設定說明操作。

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

import com.google.cloud.aiplatform.v1.CreatePipelineJobRequest;
import com.google.cloud.aiplatform.v1.LocationName;
import com.google.cloud.aiplatform.v1.PipelineJob;
import com.google.cloud.aiplatform.v1.PipelineJob.RuntimeConfig;
import com.google.cloud.aiplatform.v1.PipelineServiceClient;
import com.google.cloud.aiplatform.v1.PipelineServiceSettings;
import com.google.protobuf.Value;
import java.io.IOException;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class EmbeddingModelTuningSample {
  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running this sample.
    String apiEndpoint = "us-central1-aiplatform.googleapis.com:443";
    String project = "PROJECT";
    String baseModelVersionId = "BASE_MODEL_VERSION_ID";
    String taskType = "DEFAULT";
    String pipelineJobDisplayName = "PIPELINE_JOB_DISPLAY_NAME";
    String outputDir = "OUTPUT_DIR";
    String queriesPath = "QUERIES_PATH";
    String corpusPath = "CORPUS_PATH";
    String trainLabelPath = "TRAIN_LABEL_PATH";
    String testLabelPath = "TEST_LABEL_PATH";
    double learningRateMultiplier = 1.0;
    int outputDimensionality = 768;
    int batchSize = 128;
    int trainSteps = 1000;

    createEmbeddingModelTuningPipelineJob(
        apiEndpoint,
        project,
        baseModelVersionId,
        taskType,
        pipelineJobDisplayName,
        outputDir,
        queriesPath,
        corpusPath,
        trainLabelPath,
        testLabelPath,
        learningRateMultiplier,
        outputDimensionality,
        batchSize,
        trainSteps);
  }

  public static PipelineJob createEmbeddingModelTuningPipelineJob(
      String apiEndpoint,
      String project,
      String baseModelVersionId,
      String taskType,
      String pipelineJobDisplayName,
      String outputDir,
      String queriesPath,
      String corpusPath,
      String trainLabelPath,
      String testLabelPath,
      double learningRateMultiplier,
      int outputDimensionality,
      int batchSize,
      int trainSteps)
      throws IOException {
    Matcher matcher = Pattern.compile("^(?<Location>\\w+-\\w+)").matcher(apiEndpoint);
    String location = matcher.matches() ? matcher.group("Location") : "us-central1";
    String templateUri =
        "https://us-kfp.pkg.dev/ml-pipeline/llm-text-embedding/tune-text-embedding-model/v1.1.4";
    PipelineServiceSettings settings =
        PipelineServiceSettings.newBuilder().setEndpoint(apiEndpoint).build();
    try (PipelineServiceClient client = PipelineServiceClient.create(settings)) {
      Map<String, Value> parameterValues =
          Map.of(
              "base_model_version_id", valueOf(baseModelVersionId),
              "task_type", valueOf(taskType),
              "queries_path", valueOf(queriesPath),
              "corpus_path", valueOf(corpusPath),
              "train_label_path", valueOf(trainLabelPath),
              "test_label_path", valueOf(testLabelPath),
              "learning_rate_multiplier", valueOf(learningRateMultiplier),
              "output_dimensionality", valueOf(outputDimensionality),
              "batch_size", valueOf(batchSize),
              "train_steps", valueOf(trainSteps));
      PipelineJob pipelineJob =
          PipelineJob.newBuilder()
              .setTemplateUri(templateUri)
              .setDisplayName(pipelineJobDisplayName)
              .setRuntimeConfig(
                  RuntimeConfig.newBuilder()
                      .setGcsOutputDirectory(outputDir)
                      .putAllParameterValues(parameterValues)
                      .build())
              .build();
      CreatePipelineJobRequest request =
          CreatePipelineJobRequest.newBuilder()
              .setParent(LocationName.of(project, location).toString())
              .setPipelineJob(pipelineJob)
              .build();
      return client.createPipelineJob(request);
    }
  }

  private static Value valueOf(String s) {
    return Value.newBuilder().setStringValue(s).build();
  }

  private static Value valueOf(int n) {
    return Value.newBuilder().setNumberValue(n).build();
  }

  private static Value valueOf(double n) {
    return Value.newBuilder().setNumberValue(n).build();
  }
}

Node.js

在試用這個範例之前,請先按照「使用用戶端程式庫的 Agent Platform 快速入門導覽課程」中的 Node.js 設定說明操作。

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

async function main(
  apiEndpoint,
  project,
  outputDir,
  pipelineJobDisplayName = 'embedding-customization-pipeline-sample',
  baseModelVersionId = 'text-embedding-005',
  taskType = 'DEFAULT',
  corpusPath = 'gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/corpus.jsonl',
  queriesPath = 'gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/queries.jsonl',
  trainLabelPath = 'gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/train.tsv',
  testLabelPath = 'gs://cloud-samples-data/ai-platform/embedding/goog-10k-2024/r11/test.tsv',
  outputDimensionality = 768,
  learningRateMultiplier = 1.0,
  batchSize = 128,
  trainSteps = 1000
) {
  const aiplatform = require('@google-cloud/aiplatform');
  const {PipelineServiceClient} = aiplatform.v1;
  const {helpers} = aiplatform; // helps construct protobuf.Value objects.

  const client = new PipelineServiceClient({apiEndpoint});
  const match = apiEndpoint.match(/(?<L>\w+-\w+)/);
  const location = match ? match.groups.L : 'us-central1';
  const parent = `projects/${project}/locations/${location}`;
  const params = {
    base_model_version_id: baseModelVersionId,
    task_type: taskType,
    queries_path: queriesPath,
    corpus_path: corpusPath,
    train_label_path: trainLabelPath,
    test_label_path: testLabelPath,
    batch_size: batchSize,
    train_steps: trainSteps,
    output_dimensionality: outputDimensionality,
    learning_rate_multiplier: learningRateMultiplier,
  };
  const runtimeConfig = {
    gcsOutputDirectory: outputDir,
    parameterValues: Object.fromEntries(
      Object.entries(params).map(([k, v]) => [k, helpers.toValue(v)])
    ),
  };
  const pipelineJob = {
    templateUri:
      'https://us-kfp.pkg.dev/ml-pipeline/llm-text-embedding/tune-text-embedding-model/v1.1.4',
    displayName: pipelineJobDisplayName,
    runtimeConfig,
  };
  async function createTuneJob() {
    const [response] = await client.createPipelineJob({parent, pipelineJob});
    console.log(`job_name: ${response.name}`);
    console.log(`job_state: ${response.state}`);
  }

  await createTuneJob();
}

控制台

如要使用 Google Cloud 控制台調整文字嵌入模型,請按照下列步驟啟動自訂管道:

  1. 前往 Google Cloud 控制台「Agent Platform」部分的「Gemini Enterprise Agent Platform Pipelines」頁面。

    前往 Gemini Enterprise Agent Platform Pipelines

  2. 按一下「建立執行作業」,開啟「建立管道執行作業」窗格。
  3. 點選「Select from existing pipelines」(從現有的管道中選取),然後輸入下列詳細資料:
    1. 從「選取資源」下拉式選單中選取「ml-pipeline」。
    2. 在「Repository」(存放區) 下拉式選單中,選取「llm-text-embedding」。
    3. 從「Pipeline or component」(管道或元件) 下拉式選單中,選取「tune-text-embedding-model」。
    4. 從「版本」下拉式選單中,選取標示為「v1.1.3」的版本。
  4. 指定「Run name」(執行作業名稱),以便識別管道執行作業。
  5. 在「Region」(區域) 下拉式選單中,選取要建立管道執行的區域,這個區域會與建立調整模型的區域相同。
  6. 按一下「繼續」。「Runtime configuration」(執行階段設定) 窗格隨即顯示。
  7. 在「Cloud storage location」(Cloud Storage 位置)下方,按一下「Browse」(瀏覽),選取要儲存管道輸出構件的 Cloud Storage bucket,然後點選「Select」(選取)。
  8. 在「Pipeline parameters」(管道參數) 下方,指定調整管道的參數。三個必要參數分別是 corpus_path、queries_path 和 train_label_path,格式請參閱「準備嵌入資料集」。如要進一步瞭解各項參數,請參閱本節的「REST」分頁。
  9. 按一下「Submit」(提交),建立管道執行作業。

其他支援的功能

文字嵌入調整功能支援 VPC Service Controls,您可以在建立 PipelineJob 時傳遞 network 參數,設定在虛擬私有雲 (VPC) 中執行。

如要使用客戶自行管理的加密金鑰 (CMEK),請將金鑰傳遞至 parameterValues.encryption_spec_key_name 管道參數,「以及」建立 PipelineJob 時的 encryptionSpec.kmsKeyName 參數。

使用調整後的模型

在 Model Registry 查看調整後的模型

調整工作完成後,調整後的模型不會自動部署至端點。並在 Model Registry 中以模型資源的形式提供。您可以使用Google Cloud 控制台,查看目前專案中的模型清單,包括調整後的模型。

如要在 Google Cloud 控制台查看經過微調的模型,請前往 Gemini Enterprise Agent Platform 的「Model Registry」頁面。

前往 Gemini Enterprise Agent Platform 的 Model Registry

部署模型

調整嵌入模型後,您需要部署模型資源。如要部署調整後的嵌入模型,請參閱「將模型部署至端點」。

與基礎模型不同,調整後的文字嵌入模型是由使用者管理。包括管理機器類型和加速器等供應資源。為避免推論期間發生記憶體不足錯誤,建議您使用 NVIDIA_TESLA_A100 GPU 類型部署,這種類型可支援任何輸入長度,批次大小最多可達 5。

調整後的模型最多支援 3072 個詞元,並可截斷較長的輸入內容。

取得已部署模型的推論結果

部署調整後的模型後,您可以使用下列其中一個指令,向調整後的模型端點發出要求。

調整後 textembedding-gecko@001 模型的 curl 指令範例

如要從調整後的 textembedding-gecko@001 版本取得推論,請使用下列 curl 指令範例。

PROJECT_ID=PROJECT_ID
LOCATION=LOCATION
ENDPOINT_URI=https://${LOCATION}-aiplatform.googleapis.com
MODEL_ENDPOINT=TUNED_MODEL_ENDPOINT_ID

curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json"  \
    ${ENDPOINT_URI}/v1/projects/${PROJECT_ID}/locations/${LOCATION}/endpoints/${MODEL_ENDPOINT}:predict \
    -d '{
  "instances": [
    {
      "content": "Dining in New York City"
    },
    {
      "content": "Best resorts on the east coast"
    }
  ]
}'

非 textembedding-gecko@001 模型的 curl 指令範例

其他模型的調整版本 (例如 textembedding-gecko@003 和 textembedding-gecko-multilingual@001) 需要 2 個額外輸入內容:task_type 和 title。如要進一步瞭解這些參數,請參閱 curl 指令

PROJECT_ID=PROJECT_ID
LOCATION=LOCATION
ENDPOINT_URI=https://${LOCATION}-aiplatform.googleapis.com
MODEL_ENDPOINT=TUNED_MODEL_ENDPOINT_ID

curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json"  \
    ${ENDPOINT_URI}/v1/projects/${PROJECT_ID}/locations/${LOCATION}/endpoints/${MODEL_ENDPOINT}:predict \
    -d '{
  "instances": [
    {
      "content": "Dining in New York City",
      "task_type": "DEFAULT",
      "title": ""
    },
    {
      "content": "There are many resorts to choose from on the East coast...",
      "task_type": "RETRIEVAL_DOCUMENT",
      "title": "East Coast Resorts"
    }
  ]
}'

輸出範例

對已部署的調整模型提出推論要求時,輸出內容的格式與對文字嵌入 API 提出要求的輸出內容不同。

{
 "predictions": [
   [ ... ],
   [ ... ],
   ...
 ],
 "deployedModelId": "...",
 "model": "projects/.../locations/.../models/...",
 "modelDisplayName": "tuned-text-embedding-model",
 "modelVersionId": "1"
}

後續步驟