

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

# TwelveLabs Marengo Embed 2.7
<a name="model-parameters-marengo"></a>

此 TwelveLabs Marengo Embed 2.7 模型會從影片、文字、音訊或影像輸入產生嵌入。這些嵌入可用於相似性搜尋、叢集和其他機器學習任務。
+ 供應商 — TwelveLabs
+ 模型 ID — twelvelabs.marengo-embed-2-7-v1:0

此 TwelveLabs Marengo Embed 2.7 模型支援下表中的 Amazon Bedrock 執行時期操作。
+ 如需不同 API 方法使用案例的詳細資訊，請參閱 [了解不同模型推論方法的使用案例不同的推論方法](inference-methods.md)。
+ 如需關於模型類型的詳細資訊，請參閱 [Amazon Bedrock 中的推論運作方式推論運作方式](inference-how.md)。
  + 如需模型 IDs 的清單，以及查看 中TwelveLabs Marengo Embed 2.7支援的模型和AWS區域，請在 的表格中搜尋模型[Amazon Bedrock 中支援的基礎模型](models-supported.md)。
  + 如需推論設定檔 ID 的完整清單，請參閱 [推論設定檔支援的區域和模型](inference-profiles-support.md)。推論設定檔 ID 是以 AWS區域為基礎。


****  

| API 操作 | 支援的模型類型 | 輸入模態 | 輸出模態 | 
| --- | --- | --- | --- | 
|  InvokeModel  | [推論設定檔](inference-profiles-support.md) |  文字 影像  |  內嵌項目  | 
| StartAsyncInvoke | [基礎模型](models-supported.md) |  影片 音訊 影像 文字  |  嵌入項目  | 

**注意**  
使用 `InvokeModel` 產生搜尋查詢的嵌入。使用 `StartAsyncInvoke` 大規模產生資產的嵌入。

輸入有下列配額：


****  

| 輸入模式 | 上限 | 
| --- | --- | 
| 文字 | 77 個字符 | 
| 影像 | 5 MB | 
| 影片 (S3) | 2 GB | 
| 音訊 (S3) | 2 GB | 

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

**Topics**
+ [TwelveLabs Marengo Embed 2.7 請求參數](#model-parameters-marengo-async-request)
+ [TwelveLabs Marengo Embed 2.7 回應](#model-parameters-marengo-response)
+ [TwelveLabs Marengo Embed 2.7 程式碼範例](#model-parameters-marengo-examples)

## TwelveLabs Marengo Embed 2.7 請求參數
<a name="model-parameters-marengo-async-request"></a>

當您提出請求時，指定模型特定輸入所在的欄位取決於 API 操作：
+ [InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html) – 在請求 `body` 中。
+ [StartAsyncInvoke](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_StartAsyncInvoke.html) – 在請求內文的 `modelInput` 欄位中。

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

------
#### [ 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
}
```

------

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

### inputType
<a name="model-parameters-marengo-inputType"></a>

嵌入的模式。
+ **類型：**字串
+ **必要**：是
+ **有效值**：`video` \$1 `text` \$1 `audio` \$1 `image`

### inputText
<a name="model-parameters-marengo-inputText"></a>

要嵌入的文字。
+ **類型：**字串
+ **必要：**是 (適用於相容輸入類型)
+ **相容輸入類型：**文字

### textTruncate
<a name="model-parameters-marengo-textTruncate"></a>

指定平台如何截斷文字。
+ **類型：**字串
+ **必要**：否
+ **有效值**：
  + `end` – 截斷文字的結尾。
  + `none` – 如果文字超過限制，則傳回錯誤
+ **預設值：** 結尾
+ **相容輸入類型：**文字

### mediaSource
<a name="model-parameters-marengo-mediaSource"></a>

包含媒體來源的相關資訊。
+ **類型：**物件
+ **必要：**是 (如果相容類型)
+ **相容輸入類型：**影像、影片、音訊

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

  ```
  {
      "mediaSource": {
          "base64String": "base64-encoded string"
      }
  }
  ```
  + `base64String` – 媒體的 Base64 編碼字串。
+ **S3 位置** – 指定 S3 URI 和儲存貯體擁有者。

  ```
  {
      "s3Location": {
          "uri": "string",
          "bucketOwner": "string"
      }
  }
  ```
  + `uri` – 包含媒體的 S3 URI。
  + `bucketOwner` – S3 儲存貯體擁有者AWS的帳戶 ID。

### embeddingOption
<a name="model-parameters-marengo-embeddingOption"></a>

指定要擷取的嵌入類型。
+ **類型：**清單
+ **必要**：否
+ **清單成員的有效值：**
  + `visual-text` – 針對文字搜尋最佳化的視覺化嵌入。
  + `visual-image` – 針對影像搜尋最佳化的視覺化嵌入。
  + `audio` – 影片中音訊的嵌入。
+ **預設值：**["visual-text", "visual-image", "audio"]
+ **相容輸入類型：**影片、音訊

### startSec
<a name="model-parameters-marengo-startSec"></a>

剪輯中處理應開始的時間點，以秒為單位。
+ **類型**：Double
+ **必要**：否
+ **最小值**：0
+ **預設值：**0
+ **相容輸入類型：**影片、音訊

### lengthSec
<a name="model-parameters-marengo-lengthSec"></a>

以秒為單位的時間，從 `startSec` 時間點開始計數，在此時間之後處理應停止。
+ **類型**：Double
+ **必要**：否
+ **有效值：**0 - 媒體持續時間
+ **預設值：**媒體持續時間
+ **相容輸入類型：**影片、音訊

範例：
+ startSec：5
+ lengthSec：20
+ 結果：剪輯會從 0：05 處理至 0：25 (5 秒 \$1 20 秒）。

### useFixedLengthSec
<a name="model-parameters-marengo-useFixedLengthSec"></a>

模型應產生其嵌入之每個剪輯的持續時間。
+ **類型**：Double
+ **必要**：否
+ **值參數：**2 - 10。必須大於或等於 `minClipSec`。
+ **預設值：**視媒體類型而定：
  + **影片：**動態除以鏡頭邊界偵測。
  + **音訊：**與區段平均分割，盡可能接近 10 秒。

    範例：
    + 50 秒剪輯分為 5 個 10 秒區段。
    + 16 秒剪輯分為 2 個 8 秒區段。
+ **相容輸入類型：**影片、音訊
+ **注意：**必須大於或等於 `minClipSec`。

### minClipSec
<a name="model-parameters-marengo-minClipSec"></a>

設定每個剪輯的最小值，以秒為單位。
+ **類型：**整數
+ **必要**：否
+ **值參數：**範圍：1-5
+ **預設值：**4
+ **相容輸入類型：**影片
+ **注意：**必須小於或等於 `useFixedLengthSec`。

## TwelveLabs Marengo Embed 2.7 回應
<a name="model-parameters-marengo-response"></a>

輸出嵌入和相關聯中繼資料的位置取決於調用方法：
+ [InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html) – 在回應內文中。
+ [StartAsyncInvoke](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_StartAsyncInvoke.html) – 當非同步調用任務完成後，在 `s3OutputDataConfig` 中定義的 S3 儲存貯體中。

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

輸出嵌入向量的格式如下：

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

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

### 嵌入項目
<a name="model-parameters-marengo-embedding"></a>

輸入的嵌入向量表示法。
+ **類型**：雙精度浮點數清單

### embeddingOption
<a name="model-parameters-marengo-embeddingOption"></a>

嵌入的類型。
+ **類型：**字串
+ **可能的值：**
  + `visual-text` – 針對文字搜尋最佳化的視覺化嵌入。
  + `visual-image` – 針對影像搜尋最佳化的視覺化嵌入。
  + `audio` – 影片中音訊的嵌入。
+ **相容輸入類型：**影片

### startSec
<a name="model-parameters-marengo-startSec"></a>

剪輯的開始位移。
+ **類型**：Double
+ **相容輸入類型：**影片、音訊

### endSec
<a name="model-parameters-marengo-endSec"></a>

剪輯的結束位移，以秒為單位。
+ **類型**：Double
+ **相容輸入類型：**影片、音訊

## TwelveLabs Marengo Embed 2.7 程式碼範例
<a name="model-parameters-marengo-examples"></a>

本節說明如何使用 Python 搭配不同的輸入類型使用 TwelveLabs Marengo Embed 2.7 模型。這些範例示範如何定義模型特定的輸入和執行模型調用。

**注意**  
InvokeModel 僅支援文字和影像輸入。對於視訊和音訊輸入，請使用 StartAsyncInvoke。

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

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

------