

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# TwelveLabs Marengo 嵌入 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.md)。
+ 有关模型类型的更多信息，请参阅 [提出推理请求](inference.md)。
  + 要查看模型 ID 列表以及中支持的模型和 AWS 区域TwelveLabs Marengo Embed 2.7，请在表格中搜索模型[Amazon Bedrock 中支持的根基模型](models-supported.md)。
  + 有关推理配置文件 ID 的完整列表，请参阅[支持推理配置文件的区域和模型](inference-profiles-support.md)。推理配置文件 ID 基于 AWS 区域。


****  

| API 操作 | 受支持的模型类型 | 输入模式 | 输出模态 | 
| --- | --- | --- | --- | 
| InvokeModel | [推理配置文件](inference-profiles-support.md) | 文本<br />Image | 嵌入 | 
| StartAsyncInvoke | [基础模型](models-supported.md) | 视频<br />音频<br />Image<br />文本 | 嵌入 | 

**注意**  
使用 `InvokeModel` 可为搜索查询生成嵌入。使用 `StartAsyncInvoke` 可为大规模资源生成嵌入。

以下配额适用于输入：


****  

| 输入模态 | 最大值 | 
| --- | --- | 
| 文本 | 77 个代币 | 
| Image | 5 MB | 
| 视频（S3） | 2 GB | 
| 音频（S3） | 2 GB | 

**注意**  
如果您使用 base64 编码以内嵌方式定义音频或视频，请确保请求正文有效载荷不超过 Amazon Bedrock 的 25 MB 模型调用配额。

**Topics**
+ [TwelveLabs Marengo 嵌入 2.7 请求参数](#model-parameters-marengo-async-request)
+ [TwelveLabs Marengo 嵌入 2.7 响应](#model-parameters-marengo-response)
+ [TwelveLabs Marengo 嵌入 2.7 代码示例](#model-parameters-marengo-examples)

## TwelveLabs Marengo 嵌入 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` \| `text` \| `audio` \| `image`

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

要嵌入的文本。
+ **类型**：字符串
+ **必需：**是（适用于兼容的输入类型）
+ **兼容的输入类型：**文本

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

指定平台如何截断文本。
+ **类型**：字符串
+ **必需**：否
+ **有效值：**
  + `end` – 截断文本的结尾。
  + `none` – 如果文本超过限制，则返回错误
+ **默认值：**end
+ **兼容的输入类型：**文本

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

包含有关媒体源的信息。
+ **类型：**对象
+ **必需：**是（如果是兼容的类型）
+ **兼容的输入类型：**图像、视频、音频

请求正文中`mediaSource`对象的格式取决于媒体是定义为 Base64-encoded 字符串还是 S3 位置。
+ **Base64-encoded string**

  ```
  {
      "mediaSource": {
          "base64String": "base64-encoded string"
      }
  }
  ```
  + `base64String`— 媒体 Base64-encoded 字符串。
+ **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>

剪辑中应开始处理的时间点（以秒为单位）。
+ **类型**：双精度
+ **必需**：否
+ **最小值：**0
+ **默认值：**0
+ **兼容的输入类型：**视频、音频

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

从 `startSec` 时间点起算，经过该时长（以秒为单位）后，处理应停止。
+ **类型**：双精度
+ **必需**：否
+ **有效值：**0 - 媒体时长
+ **默认值：**媒体时长
+ **兼容的输入类型：**视频、音频

示例：
+ startSec：5
+ lengthSec：20
+ 结果：片段的处理时间为 0:05 到 0:25（5 秒 \+ 20 秒）。

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

模型应为每个剪辑生成嵌入的时长。
+ **类型**：双精度
+ **必需**：否
+ **取值参数：**2 - 10。必须大于或等于 `minClipSec`。
+ **默认值：**取决于媒体类型：
  + **视频：**按镜头边界检测动态划分。
  + **音频：**均匀分割，片段尽可能接近 10 秒。

    示例：
    + 一个 50 秒的片段分为 5 个 10 秒的片段。
    + 一个 16 秒的片段分为 2 个 8 秒的片段。
+ **兼容的输入类型：**视频、音频
+ **注意：**必须大于或等于 `minClipSec`。

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

设置每个剪辑的最小值（以秒为单位）。
+ **类型：**int
+ **必需**：否
+ **取值参数：**范围：1-5
+ **默认值：**4
+ **兼容的输入类型：**视频
+ **注意：**必须小于或等于 `useFixedLengthSec`。

## TwelveLabs Marengo 嵌入 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)— 在中定义的 S3 存储桶中`s3OutputDataConfig`，在异步调用任务完成后。

如果有多个嵌入向量，则输出将为一个对象列表，每个对象均包含一个向量及其关联的元数据。

输出嵌入向量的格式如下所示：

```
{
    "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>

剪辑的起始偏移量。
+ **类型**：双精度
+ **兼容的输入类型：**视频、音频

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

剪辑的结束偏移量（以秒为单位）。
+ **类型**：双精度
+ **兼容的输入类型：**视频、音频

## TwelveLabs Marengo 嵌入 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}")
```

------