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 – テキストが制限を超えた場合にエラーを返します

  • デフォルト値: end

  • 互換性のある入力タイプ: テキスト

メディアソースに関する情報が含まれます。

  • タイプ: オブジェクト

  • 必須: はい (互換性のあるタイプの場合)

  • 互換性のある入力タイプ: 画像、動画、音声

リクエスト本文内の mediaSource オブジェクトの形式は、メディアが Base64 でエンコードされた文字列として定義されているか、S3 の場所として定義されているかによって異なります。

  • Base64 でエンコードされた文字列

    { "mediaSource": { "base64String": "base64-encoded string" } }
    • base64String – メディアに対して Base64 でエンコードされた文字列。

  • 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"]

  • 互換性のある入力タイプ: 動画、音声

処理が開始されるクリップの時点 (秒単位)。

  • タイプ: ダブル

  • 必須: いいえ

  • 最小値: 0

  • デフォルト値 - 0

  • 互換性のある入力タイプ: 動画、音声

処理を停止するまでの時間 (秒単位)。startSec 時点からカウントされます。

  • タイプ: ダブル

  • 必須: いいえ

  • 有効な値: 0~メディアの時間

  • デフォルト値: メディアの時間

  • 互換性のある入力タイプ: 動画、音声

例:

  • startSec: 5

  • lengthSec: 20

  • 結果: クリップは 0:05 から 0:20 まで処理されます。

モデルが埋め込みを生成する対象となる各クリップの時間。

  • タイプ: ダブル

  • 必須: いいえ

  • 値パラメータ: 2~10。minClipSec 以上である必要があります。

  • デフォルト値: メディアのタイプによって異なります。

    • 動画: ショット境界検出で動的に分割されます

    • 音声: 均等に、かつできる限り 10 に近くなるように分割されます。例:

      • 50 秒のクリップは 10 秒の 5 つのセグメントに分割されます。

      • 16 秒のクリップは 8 秒の 2 つのセグメントに分割されます。

  • 互換性のある入力タイプ: – 動画、音声

  • 注: 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 }

レスポンスパラメータの詳細については、次のセクションを展開してください。

入力のベクトル表現を埋め込みます。

  • タイプ: double のリスト

埋め込みのタイプ。

  • タイプ: 文字列

  • 使用できる値: 、、、、、。

    • visual-text – テキスト検索用に最適化されたビジュアル埋め込み。

    • visual-image – 画像検索用に最適化されたビジュアル埋め込み。

    • audio – 動画内の音声の埋め込み。

  • 互換性のある入力タイプ: 動画

クリップの開始オフセット。

  • タイプ: ダブル

  • 互換性のある入力タイプ: 動画、音声

クリップの終了オフセット (秒単位)。

  • タイプ: ダブル

  • 互換性のある入力タイプ: 動画、音声

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}")