TwelveLabs Marengo Embed 2.7 - Amazon Bedrock

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

TwelveLabs Marengo Embed 2.7

TwelveLabs Marengo Embed 2.7 模型會從視訊、文字、音訊或影像輸入產生內嵌。這些內嵌可用於相似性搜尋、叢集和其他機器學習任務。

  • 提供者 — TwelveLabs

  • 模型 ID — twelvelabs.marengo-embed-2-7-v1:0

TwelveLabs Marengo Embed 2.7 模型支援下表中的 Amazon Bedrock 執行期操作。

API 操作 支援的模型類型 輸入模態 輸出模態

InvokeModel

推論設定檔

文字

映像

內嵌項目

StartAsyncInvoke 基礎模型

影片

音訊

映像

文字

內嵌項目

注意

使用 InvokeModel 來產生搜尋查詢的內嵌。使用 StartAsyncInvoke為大規模資產產生內嵌。

下列配額適用於輸入:

輸入模式 最大
文字 77 個字符
映像 5 MB
影片 (S3) 2 GB
音訊 (S3) 2 GB
注意

如果您使用 base64 編碼定義音訊或視訊內嵌,請確保請求內文承載不超過 Amazon Bedrock 25 MB 模型調用配額。

TwelveLabs Marengo Embed 2.7 請求參數

當您提出請求時,指定模型特定輸入的欄位取決於 API 操作:

模型輸入的格式取決於輸入模式:

Text
{ "inputType": "text", "inputText": "string", "textTruncate": "string }
Inline image
{ "inputType": "image", "mediaSource": { "base64String": "base64-encoded string" } }
S3 image
{ "inputType": "image", "mediaSource": { "s3Location": { "uri": "string", "bucketOwner": "string" } } }
Inline video
{ "inputType": "video", "mediaSource": { "s3Location": { "base64String": "base64-encoded string" } }, "startSec": double, "lengthSec": double, "useFixedLengthSec": double, "embeddingOption": "visual-text" | "visual-image" | "audio" }
S3 video
{ "inputType": "image", "mediaSource": { "s3Location": { "uri": "string", "bucketOwner": "string" } }, "startSec": double, "lengthSec": double, "useFixedLengthSec": double, "minClipSec": int, "embeddingOption": ["string"] }
Inline audio
{ "inputType": "audio", "mediaSource": { "base64String": "base64-encoded string" }, "startSec": double, "lengthSec": double, "useFixedLengthSec": double }
S3 audio
{ "inputType": "audio", "mediaSource": { "s3Location": { "uri": "string", "bucketOwner": "string" } }, "startSec": double, "lengthSec": double, "useFixedLengthSec": double }

如需輸入參數的詳細資訊,請展開下列各節:

內嵌的模式。

  • 類型:字串

  • 必要:是

  • 有效值video | text | audio | image

要內嵌的文字。

  • 類型:字串

  • 必要:是 (適用於相容的輸入類型)

  • 相容輸入類型:文字

指定平台如何截斷文字。

  • 類型:字串

  • 必要:否

  • 有效值

    • end – 截斷文字的結尾。

    • none – 如果文字超過限制,則傳回錯誤

  • 預設值:結束

  • 相容輸入類型:文字

包含媒體來源的相關資訊。

  • 類型:物件

  • 必要:是 (如果相容類型)

  • 相容輸入類型:Image、Video、Audio

請求內文中mediaSource物件的格式取決於媒體是定義為 Base64-encoded字串還是 S3 位置。

  • Base64-encoded字串

    { "mediaSource": { "base64String": "base64-encoded string" } }
    • base64String – 媒體的 Base64-encoded字串。

  • S3 位置 – 指定 S3 URI 和

    { "s3Location": { "uri": "string", "bucketOwner": "string" } }
    • uri – 包含媒體的 S3 URI。

    • bucketOwner – S3 儲存貯體擁有者 AWS 的帳戶 ID。

指定要擷取的內嵌類型。

  • 類型:列出

  • 必要:否

  • 清單成員的有效值:

    • visual-text – 針對文字搜尋最佳化的視覺化內嵌。

    • visual-image – 針對影像搜尋最佳化的視覺化內嵌。

    • audio – 影片中音訊的內嵌。

  • 預設值:【"visual-text"、"visual-image"、"audio"】

  • 相容輸入類型:影片、音訊

應開始處理的剪輯時間點,以秒為單位。

  • 類型:Double

  • 必要:否

  • 最小值:0

  • 預設值:0

  • 相容輸入類型:影片、音訊

以秒為單位的時間,從startSec時間點開始計數,之後應停止處理。

  • 類型:Double

  • 必要:否

  • 有效值:0 - 媒體持續時間

  • 預設值:媒體持續時間

  • 相容輸入類型:影片、音訊

例如:

  • startSec:5

  • lengthSec:20

  • 結果:剪輯將從 0:05 處理至 0:20。

模型應產生內嵌之每個剪輯的持續時間。

  • 類型:Double

  • 必要:否

  • 值參數:2 - 10。必須大於或等於 minClipSec

  • 預設值:視媒體類型而定:

    • 影片:動態除以鏡頭邊界偵測

    • 音訊:平均分割,盡可能接近 10。例如:

      • 50 秒剪輯會分為 5 個 10 秒區段。

      • 16 秒剪輯會分為 2 個 8 秒區段。

  • 相容輸入類型:– 視訊、音訊

  • 注意:必須大於或等於 minClipSec

設定每個剪輯的最小值,以秒為單位。

  • 類型:int

  • 必要:否

  • 值參數:範圍:1-5

  • 預設值:4

  • 相容輸入類型:影片

  • 注意:必須小於或等於 useFixedLengthSec

TwelveLabs Marengo Embed 2.7 回應

輸出內嵌和相關聯中繼資料的位置取決於叫用方法:

  • InvokeModel – 在回應內文中。

  • StartAsyncInvoke – 在非同步調用任務完成後s3OutputDataConfig,在 中定義的 S3 儲存貯體中。

如果有多個內嵌向量,則輸出是物件清單,每個物件都包含向量及其相關聯的中繼資料。

輸出內嵌向量的格式如下:

{ "embedding": ["string"], "embeddingOption": "visual-text" | "visual-image" | "audio", "startSec": double, "endsec": double }

如需回應參數的詳細資訊,請展開下列各節:

內嵌輸入向量表示法。

  • 類型:雙工清單

內嵌項目的類型。

  • 類型:字串

  • 可能的值:

    • visual-text – 針對文字搜尋最佳化的視覺化內嵌。

    • visual-image – 針對影像搜尋最佳化的視覺化內嵌。

    • audio – 影片中音訊的內嵌。

  • 相容輸入類型:影片

剪輯的開始位移。

  • 類型:Double

  • 相容輸入類型:影片、音訊

剪輯的結束位移,以秒為單位。

  • 類型:Double

  • 相容輸入類型:影片、音訊

TwelveLabs Marengo Embed 2.7 程式碼範例

本節說明如何使用 Python 搭配不同的輸入類型使用TwelveLabs Marengo Embed 2.7模型。

注意

目前,InvokeModel 僅支援文字和影像輸入。

依照下列步驟將您的程式碼放在一起:

1. 定義模型特定的輸入

根據您的輸入類型定義模型特定的輸入:

Text
# Create the model-specific input model_id = "twelvelabs.marengo-embed-2-7-v1:0" # Replace the us prefix depending on your region inference_profile_id = "us.twelvelabs.marengo-embed-2-7-v1:0" model_input = { "inputType": "text", "inputText": "man walking a dog" }
Inline image
# Create the model-specific input model_id = "twelvelabs.marengo-embed-2-7-v1:0" # Replace the us prefix depending on your region inference_profile_id = "us.twelvelabs.marengo-embed-2-7-v1:0" model_input = { "inputType": "image", "mediaSource": { "base64String": "example-base64-image" } }
S3 image
# Create the model-specific input model_id = "twelvelabs.marengo-embed-2-7-v1:0" # Replace the us prefix depending on your region inference_profile_id = "us.twelvelabs.marengo-embed-2-7-v1:0" model_input = { "inputType": "image", "mediaSource": { "s3Location": { "uri": "s3://amzn-s3-demo-bucket/my_image.png", "bucketOwner": "123456789012" } } }
Inline video
# Create the model-specific input model_id = "twelvelabs.marengo-embed-2-7-v1:0" # Replace the us prefix depending on your region inference_profile_id = "us.twelvelabs.marengo-embed-2-7-v1:0" model_input = { "inputType": "video", "mediaSource": { "base64String": "base_64_encoded_string_of_video" }, "startSec": 0, "lengthSec": 13, "useFixedLengthSec": 5, "embeddingOption": [ "visual-text", "audio" ] }
S3 video
# Create the model-specific input model_id = "twelvelabs.marengo-embed-2-7-v1:0" # Replace the us prefix depending on your region inference_profile_id = "us.twelvelabs.marengo-embed-2-7-v1:0" model_input = { "inputType": "video", "mediaSource": { "s3Location": { "uri": "amzn-s3-demo-bucket/my-video.mp4", "bucketOwner": "123456789012" } }, "startSec": 0, "lengthSec": 13, "useFixedLengthSec": 5, "embeddingOption": [ "visual-text", "audio" ] }
Inline audio
# Create the model-specific input model_id = "twelvelabs.marengo-embed-2-7-v1:0" # Replace the us prefix depending on your region inference_profile_id = "us.twelvelabs.marengo-embed-2-7-v1:0" model_input = { "inputType": "audio", "mediaSource": { "base64String": "base_64_encoded_string_of_audio" }, "startSec": 0, "lengthSec": 13, "useFixedLengthSec": 10 }
S3 audio
# Create the model-specific input model_id = "twelvelabs.marengo-embed-2-7-v1:0" # Replace the us prefix depending on your region inference_profile_id = "us.twelvelabs.marengo-embed-2-7-v1:0" model_input = { "inputType": "audio", "mediaSource": { "s3Location": { "uri": "s3://amzn-s3-demo-bucket/my-audio.wav", "bucketOwner": "123456789012" } }, "startSec": 0, "lengthSec": 13, "useFixedLengthSec": 10 }
2. 使用模型輸入執行模型調用

然後,新增對應於您選擇的模型調用方法的程式碼片段。

InvokeModel
# Run model invocation with InvokeModel import boto3 import json # Initialize the Bedrock Runtime client client = boto3.client('bedrock-runtime') # Make the request response = client.invoke_model( modelId=inference_profile_id, body=json.dumps(model_input) ) # Print the response body response_body = json.loads(response['body'].read().decode('utf-8')) print(response_body)
StartAsyncInvoke
# Run model invocation asynchronously import boto3 import json # Initalize the Bedrock Runtime client. client = boto3.client("bedrock-runtime") try: # Start the asynchronous job invocation = client.start_async_invoke( modelId=model_id, modelInput=model_input, outputDataConfig={ "s3OutputDataConfig": { "s3Uri": "s3://&example-s3-destination-bucket;" } } ) # Print the response JSON print("Response:") print(json.dumps(invocation, indent=2, default=str)) except Exception as e: # Implement error handling here. message = e.response["Error"]["Message"] print(f"Error: {message}")