如需其他概念資訊,請參閱「多模態嵌入」。
支援的型號:
模型 | 程式碼 |
---|---|
適用於多模態的嵌入 | multimodalembedding@001 |
語法範例
用於傳送多模態嵌入 API 要求的語法。
curl
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/publishers/google/models/${MODEL_ID}:predict \ -d '{ "instances": [ ... ], }'
Python
from vertexai.vision_models import MultiModalEmbeddingModel model = MultiModalEmbeddingModel.from_pretrained("multimodalembedding") model.get_embeddings(...)
參數清單
如需實作詳情,請參閱範例。
要求內文
{
"instances": [
{
"text": string,
"image": {
// Union field can be only one of the following:
"bytesBase64Encoded": string,
"gcsUri": string,
// End of list of possible types for union field.
"mimeType": string
},
"video": {
// Union field can be only one of the following:
"bytesBase64Encoded": string,
"gcsUri": string,
// End of list of possible types for union field.
"videoSegmentConfig": {
"startOffsetSec": integer,
"endOffsetSec": integer,
"intervalSec": integer
}
},
"parameters": {
"dimension": integer
}
}
]
}
參數 | |
---|---|
|
選用: 要為其產生嵌入的圖片。 |
|
選用: 要產生嵌入的文字。 |
|
選用: 要產生嵌入資料的影片片段。 |
|
選用: 回應中包含的嵌入維度。僅適用於文字和圖片輸入內容。接受的值: |
圖片
參數 | |
---|---|
|
選用: 以 Base64 字串編碼的圖片位元組。必須是 |
|
選用。 要進行嵌入作業的圖片 Cloud Storage 位置。請選擇 |
|
選用。 圖片內容的 MIME 類型。支援的值: |
影片
參數 | |
---|---|
|
選用: 以 Base64 字串編碼的影片位元組。請選擇 |
|
選用: 要嵌入的影片的 Cloud Storage 位置。請選擇 |
|
選用: 影片片段設定。 |
VideoSegmentConfig
參數 | |
---|---|
|
選用: 影片片段的起始偏移量 (以秒為單位)。如未指定,則會使用 |
|
選用: 影片片段的結束偏移量 (以秒為單位)。如未指定,則會使用 |
|
選用。 嵌入影片的間隔。 |
回應主體
{
"predictions": [
{
"textEmbedding": [
float,
// array of 128, 256, 512, or 1408 float values
float
],
"imageEmbedding": [
float,
// array of 128, 256, 512, or 1408 float values
float
],
"videoEmbeddings": [
{
"startOffsetSec": integer,
"endOffsetSec": integer,
"embedding": [
float,
// array of 1408 float values
float
]
}
]
}
],
"deployedModelId": string
}
回應元素 | 說明 |
---|---|
imageEmbedding |
128、256、512 或 1408 維度的浮點值清單。 |
textEmbedding |
128、256、512 或 1408 維度的浮點值清單。 |
videoEmbeddings |
1408 個浮點值的維度清單,其中包含影片片段的開始和結束時間 (以秒為單位),系統會根據這些時間產生嵌入資料。 |
範例
基本用途
從圖片產生嵌入
使用以下範例為圖片產生嵌入項目。
REST
使用任何要求資料之前,請先替換以下項目:
- LOCATION:專案所在的區域。例如
us-central1
、europe-west2
或asia-northeast3
。如需可用區域的清單,請參閱「Vertex AI 生成式 AI 位置」。 - PROJECT_ID:您的 Google Cloud 專案 ID。
- TEXT:要取得嵌入資料的目標文字。例如:
a cat
。 - B64_ENCODED_IMG:要取得嵌入資料的目標圖片。圖片必須以 Base64 編碼的位元組字串指定。
HTTP 方法和網址:
POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/multimodalembedding@001:predict
JSON 要求主體:
{ "instances": [ { "text": "TEXT", "image": { "bytesBase64Encoded": "B64_ENCODED_IMG" } } ] }
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/multimodalembedding@001:predict"
PowerShell
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/multimodalembedding@001:predict" | Select-Object -Expand Content
{ "predictions": [ { "textEmbedding": [ 0.010477379, -0.00399621, 0.00576670747, [...] -0.00823613815, -0.0169572588, -0.00472954148 ], "imageEmbedding": [ 0.00262696808, -0.00198890246, 0.0152047109, -0.0103145819, [...] 0.0324628279, 0.0284924973, 0.011650892, -0.00452344026 ] } ], "deployedModelId": "DEPLOYED_MODEL_ID" }
Python 適用的 Vertex AI SDK
如要瞭解如何安裝或更新 Python 適用的 Vertex AI SDK,請參閱「安裝 Python 適用的 Vertex AI SDK」。 詳情請參閱 Vertex AI SDK for Python API 參考說明文件。
Node.js
在試用這個範例之前,請先按照 Vertex AI 快速入門:使用用戶端程式庫中的操作說明設定 Node.js。詳情請參閱 Vertex AI Node.js API 參考說明文件。
如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Java
在試用這個範例之前,請先按照 Vertex AI 快速入門:使用用戶端程式庫中的操作說明設定 Java。詳情請參閱 Vertex AI Java API 參考說明文件。
如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Go
在試用這個範例之前,請先按照 Vertex AI 快速入門:使用用戶端程式庫中的操作說明設定 Go。詳情請參閱 Vertex AI Go API 參考說明文件。
如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
從影片產生嵌入
使用下列範例為影片內容產生嵌入資料。
REST
以下範例使用位於 Cloud Storage 中的影片。您也可以使用 video.bytesBase64Encoded
欄位,提供Base64 編碼的影片字串表示法。
使用任何要求資料之前,請先替換以下項目:
- LOCATION:專案所在的區域。例如
us-central1
、europe-west2
或asia-northeast3
。如需可用區域的清單,請參閱「Vertex AI 生成式 AI 位置」。 - PROJECT_ID:您的 Google Cloud 專案 ID。
- VIDEO_URI:要取得嵌入資料的目標影片的 Cloud Storage URI。例如:
gs://my-bucket/embeddings/supermarket-video.mp4
。您也可以以 Base64 編碼位元組字串的形式提供影片:
[...] "video": { "bytesBase64Encoded": "B64_ENCODED_VIDEO" } [...]
videoSegmentConfig
(START_SECOND、END_SECOND、INTERVAL_SECONDS)。選用。要產生嵌入資料的特定影片片段 (以秒為單位)。例如:
[...] "videoSegmentConfig": { "startOffsetSec": 10, "endOffsetSec": 60, "intervalSec": 10 } [...]
使用這個設定可指定 10 秒到 60 秒的影片資料,並為下列 10 秒的影片間隔產生嵌入:[10, 20)、[20, 30)、[30, 40)、[40, 50)、[50, 60)。這個影片間隔 (
"intervalSec": 10
) 屬於標準影片嵌入模式,因此會以標準模式的計價費率向使用者收費。如果省略
videoSegmentConfig
,服務會使用下列預設值:"videoSegmentConfig": { "startOffsetSec": 0, "endOffsetSec": 120, "intervalSec": 16 }
。這個影片間隔 ("intervalSec": 16
) 屬於Essential 影片嵌入模式,因此會以Essential 模式的定價費率向使用者收費。
HTTP 方法和網址:
POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/multimodalembedding@001:predict
JSON 要求主體:
{ "instances": [ { "video": { "gcsUri": "VIDEO_URI", "videoSegmentConfig": { "startOffsetSec": START_SECOND, "endOffsetSec": END_SECOND, "intervalSec": INTERVAL_SECONDS } } } ] }
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/multimodalembedding@001:predict"
PowerShell
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/multimodalembedding@001:predict" | Select-Object -Expand Content
回覆 (7 秒影片,未指定 videoSegmentConfig
):
{ "predictions": [ { "videoEmbeddings": [ { "endOffsetSec": 7, "embedding": [ -0.0045467657, 0.0258095954, 0.0146885719, 0.00945400633, [...] -0.0023291884, -0.00493789, 0.00975185353, 0.0168156829 ], "startOffsetSec": 0 } ] } ], "deployedModelId": "DEPLOYED_MODEL_ID" }
回應 (59 秒影片,影片片段設定為以下內容:"videoSegmentConfig": { "startOffsetSec": 0, "endOffsetSec": 60, "intervalSec": 10 }
):
{ "predictions": [ { "videoEmbeddings": [ { "endOffsetSec": 10, "startOffsetSec": 0, "embedding": [ -0.00683252793, 0.0390476175, [...] 0.00657121744, 0.013023301 ] }, { "startOffsetSec": 10, "endOffsetSec": 20, "embedding": [ -0.0104404651, 0.0357737206, [...] 0.00509833824, 0.0131902946 ] }, { "startOffsetSec": 20, "embedding": [ -0.0113538112, 0.0305239167, [...] -0.00195809244, 0.00941874553 ], "endOffsetSec": 30 }, { "embedding": [ -0.00299320649, 0.0322436653, [...] -0.00993082579, 0.00968887936 ], "startOffsetSec": 30, "endOffsetSec": 40 }, { "endOffsetSec": 50, "startOffsetSec": 40, "embedding": [ -0.00591270532, 0.0368893594, [...] -0.00219071587, 0.0042470959 ] }, { "embedding": [ -0.00458270218, 0.0368121453, [...] -0.00317760976, 0.00595594104 ], "endOffsetSec": 59, "startOffsetSec": 50 } ] } ], "deployedModelId": "DEPLOYED_MODEL_ID" }
Python 適用的 Vertex AI SDK
如要瞭解如何安裝或更新 Python 適用的 Vertex AI SDK,請參閱「安裝 Python 適用的 Vertex AI SDK」。 詳情請參閱 Vertex AI SDK for Python API 參考說明文件。
Go
在試用這個範例之前,請先按照 Vertex AI 快速入門:使用用戶端程式庫中的操作說明設定 Go。詳情請參閱 Vertex AI Go API 參考說明文件。
如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
進階用途
使用下列範例,取得影片、文字和圖片內容的嵌入資料。
針對影片嵌入功能,您可以指定影片片段和嵌入密度。
REST
以下範例使用圖片、文字和影片資料。您可以在要求主體中任意搭配使用這些資料類型。
這個範例使用位於 Cloud Storage 中的影片。您也可以使用 video.bytesBase64Encoded
欄位,提供Base64 編碼的影片字串表示法。
使用任何要求資料之前,請先替換以下項目:
- LOCATION:專案所在的區域。例如
us-central1
、europe-west2
或asia-northeast3
。如需可用區域的清單,請參閱「Vertex AI 生成式 AI 位置」。 - PROJECT_ID:您的 Google Cloud 專案 ID。
- TEXT:要取得嵌入資料的目標文字。例如:
a cat
。 - IMAGE_URI:要取得嵌入資料的目標圖片的 Cloud Storage URI。例如:
gs://my-bucket/embeddings/supermarket-img.png
。您也可以以 Base64 編碼位元組字串的形式提供圖片:
[...] "image": { "bytesBase64Encoded": "B64_ENCODED_IMAGE" } [...]
- VIDEO_URI:要取得嵌入資料的目標影片的 Cloud Storage URI。例如:
gs://my-bucket/embeddings/supermarket-video.mp4
。您也可以以 Base64 編碼位元組字串的形式提供影片:
[...] "video": { "bytesBase64Encoded": "B64_ENCODED_VIDEO" } [...]
videoSegmentConfig
(START_SECOND、END_SECOND、INTERVAL_SECONDS)。選用。要產生嵌入資料的特定影片片段 (以秒為單位)。例如:
[...] "videoSegmentConfig": { "startOffsetSec": 10, "endOffsetSec": 60, "intervalSec": 10 } [...]
使用這個設定可指定 10 秒到 60 秒的影片資料,並為下列 10 秒的影片間隔產生嵌入:[10, 20)、[20, 30)、[30, 40)、[40, 50)、[50, 60)。這個影片間隔 (
"intervalSec": 10
) 屬於標準影片嵌入模式,因此會以標準模式的定價費率向使用者收費。如果省略
videoSegmentConfig
,服務會使用下列預設值:"videoSegmentConfig": { "startOffsetSec": 0, "endOffsetSec": 120, "intervalSec": 16 }
。這個影片間隔 ("intervalSec": 16
) 屬於Essential 影片嵌入模式,因此會以Essential 模式的定價費率向使用者收費。
HTTP 方法和網址:
POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/multimodalembedding@001:predict
JSON 要求主體:
{ "instances": [ { "text": "TEXT", "image": { "gcsUri": "IMAGE_URI" }, "video": { "gcsUri": "VIDEO_URI", "videoSegmentConfig": { "startOffsetSec": START_SECOND, "endOffsetSec": END_SECOND, "intervalSec": INTERVAL_SECONDS } } } ] }
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/multimodalembedding@001:predict"
PowerShell
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/multimodalembedding@001:predict" | Select-Object -Expand Content
{ "predictions": [ { "textEmbedding": [ 0.0105433334, -0.00302835181, 0.00656806398, 0.00603460241, [...] 0.00445805816, 0.0139605571, -0.00170318608, -0.00490092579 ], "videoEmbeddings": [ { "startOffsetSec": 0, "endOffsetSec": 7, "embedding": [ -0.00673126569, 0.0248149596, 0.0128901172, 0.0107588246, [...] -0.00180952181, -0.0054573305, 0.0117037306, 0.0169312079 ] } ], "imageEmbedding": [ -0.00728622358, 0.031021487, -0.00206603738, 0.0273937676, [...] -0.00204976718, 0.00321615417, 0.0121978866, 0.0193375275 ] } ], "deployedModelId": "DEPLOYED_MODEL_ID" }
Python 適用的 Vertex AI SDK
如要瞭解如何安裝或更新 Python 適用的 Vertex AI SDK,請參閱「安裝 Python 適用的 Vertex AI SDK」。 詳情請參閱 Vertex AI SDK for Python API 參考說明文件。
Go
在試用這個範例之前,請先按照 Vertex AI 快速入門:使用用戶端程式庫中的操作說明設定 Go。詳情請參閱 Vertex AI Go API 參考說明文件。
如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
後續步驟
如需詳細說明文件,請參閱以下內容: