

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

# TwelveLabs 模型
<a name="model-parameters-twelvelabs"></a>

本部分介绍 TwelveLabs 模型的请求参数和响应字段。使用这些信息，您可以对 TwelveLabs 模型进行推理调用。该TwelveLabs Pegasus 1.2模型支持[InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html)和 [InvokeModelWithResponseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithResponseStream.html)（流式传输）操作。TwelveLabs Marengo Embed 2.7和TwelveLabs Marengo Embed 3.0模型支持[StartAsyncInvoke](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_StartAsyncInvoke.html)操作。此部分还包括展示了如何调用 TwelveLabs 模型的代码示例。要在推理操作中使用模型，您需要相关模型的模型 ID。要获取模型 ID，请参阅 [Amazon Bedrock 中支持的根基模型](models-supported.md)。

TwelveLabs 是一家领先的多模态 AI 模型提供商，专注于视频理解和分析领域。他们的高级模型通过 state-of-the-art计算机视觉和自然语言处理技术实现复杂的视频搜索、分析和内容生成功能。

Amazon Bedrock 提供三种TwelveLabs型号：
+ TwelveLabs Pegasus 1.2提供全面的视频理解和分析。
+ TwelveLabs Marengo Embed 2.7为视频、文本、音频和图像内容生成高质量的嵌入内容。
+ TwelveLabs Marengo Embed 3.0是最新的嵌入模型，具有增强的性能和功能。

这些模型可帮助您构建能够大规模处理、分析视频数据并从中获取见解的应用程序。

**TwelveLabs Pegasus 1.2**

一种具备全面视频理解与分析能力的多模态模型，涵盖了内容识别、场景检测及上下文理解领域。该模型能够分析视频内容，并生成关于视频的文本描述、见解及问题解答。

**TwelveLabs Marengo Embed 2.7**

一种多模态嵌入模型，可针对视频、文本、音频及图像内容生成高质量的向量表示，适用于相似性搜索、聚类及其他机器学习任务。该模型支持多种输入模态，并提供已针对不同的使用案例优化的专用嵌入。

**TwelveLabs Marengo Embed 3.0**

一种增强的多模态嵌入模型，它扩展了 Marengo 2.7 的功能，支持文本和图像交错输入模式。该模型生成视频、文本、音频、图像和交错文本图像内容的高质量矢量表示形式，用于相似度搜索、聚类和其他机器学习任务。

**Topics**
+ [TwelveLabs Pegasus 1.2](model-parameters-pegasus.md)
+ [TwelveLabs Marengo Embed 2.7](model-parameters-marengo.md)
+ [TwelveLabs Marengo Embed 3.0](model-parameters-marengo-3.md)

# TwelveLabs Pegasus 1.2
<a name="model-parameters-pegasus"></a>

TwelveLabs Pegasus 1.2 模型具备全面的视频理解与分析能力，能够分析视频内容，并生成关于视频的文本描述、见解及问题解答。

使用此信息对带有 InvokeModel、 InvokeModelWithResponseStream （流式传输）操作的 TwelveLabs 模型进行推理调用。
+ 提供商 – TwelveLabs
+ 类别 – 视频理解、内容分析
+ 模型 ID – `twelvelabs.pegasus-1-2-v1:0`
+ 输入模态 – 视频
+ 输出模态 – 文本
+ 最大视频大小 – 时长 1 小时的视频（文件大小 < 2 GB）

## TwelveLabs Pegasus 1.2 请求参数
<a name="model-parameters-pegasus-request"></a>

下表描述了 TwelveLabs Pegasus 1.2 模型的输入参数：


**TwelveLabs Pegasus 1.2 请求参数**  

| 字段 | 类型 | 必需 | 描述 | 
| --- | --- | --- | --- | 
| inputPrompt | 字符串 | 是 | 用于分析视频的提示。最大值：2000 个词元。 | 
| temperature | double | 否 | 模型的温度。控制输出的随机性。默认值：0.2，最小值：0，最大值：1。 | 
| responseFormat | 对象 | 否 | 可让用户指定结构化输出格式。目前仅支持 json\$1schema。 | 
| mediaSource | 对象 | 是 | 描述媒体源。必须提供 base64String 或 s3Location。 | 
| mediaSource.base64String | 字符串 | 否 | 视频的 Base64 编码字节字符串。最大值：25MB。 | 
| mediaSource.s3Location.uri | 字符串 | 否 | 可用于下载视频的 S3 URI。最大值：时长 1 小时的视频（文件大小 < 2 GB）。 | 
| mediaSource.s3Location.bucketOwner | 字符串 | 否 | 存储桶拥有者的 AWS 账户 ID。 | 
| maxOutputTokens | 整数 | 否 | 要生成的最大词元数。最大值：4096。 | 

## TwelveLabs Pegasus 1.2 响应字段
<a name="model-parameters-pegasus-response"></a>

下表描述了 TwelveLabs Pegasus 1.2 模型的输出字段：


**TwelveLabs Pegasus 1.2 响应字段**  

| 字段 | Type | 说明 | 
| --- | --- | --- | 
| message | 字符串 | 包含模型对视频的分析结果的输出消息。 | 
| finishReason | 字符串 | 描述输出终止原因的停止原因。有效值：stop（API 返回完整补全结果，未触发任何限制）、length（生成内容超出 max\$1tokens 限制）。 | 

## TwelveLabs Pegasus 1.2 请求和响应
<a name="model-parameters-pegasus-examples"></a>

以下示例展示了如何将 TwelveLabs Pegasus 1.2 模型与不同的输入源结合使用。

------
#### [ Request ]

以下示例展示了 TwelveLabs Pegasus 1.2 模型的请求格式。

**使用 base64 编码的视频：**

```
{
  "inputPrompt": "tell me about the video",
  "mediaSource": {
      "base64String": "<BASE64 STRING OF VIDEO FILE>"
  },
  "temperature": 0
}
```

**使用 S3 存储的视频：**

```
{
    "inputPrompt": "Tell me about this video",
    "mediaSource": {
        "s3Location": {
            "uri": "s3://path-to-video-object-in-s3",
            "bucketOwner": "bucket-owner-account-id"
        }
    },
    "temperature": 0
}
```

**使用结构化输出格式：**

```
{
    "inputPrompt": "Analyze this video and provide a structured summary",
    "mediaSource": {
        "s3Location": {
            "uri": "s3://path-to-video-object-in-s3",
            "bucketOwner": "bucket-owner-account-id"
        }
    },
    "temperature": 0.2,
    "maxOutputTokens": 2048,
    "responseFormat": {
        "type": "json_schema",
        "json_schema": {
            "name": "video_analysis",
            "schema": {
                "type": "object",
                "properties": {
                    "summary": {"type": "string"},
                    "key_scenes": {"type": "array", "items": {"type": "string"}},
                    "duration": {"type": "string"}
                },
                "required": ["summary", "key_scenes"]
            }
        }
    }
}
```

------
#### [ Response ]

以下示例展示了来自 TwelveLabs Pegasus 1.2 模型的响应格式。

**标准响应：**

```
{
  "message": "This video shows a person walking through a park during sunset. The scene includes trees, a walking path, and golden lighting from the setting sun. The person appears to be enjoying a peaceful evening stroll.",
  "finishReason": "stop"
}
```

**带结构化输出的响应：**

```
{
  "message": "{\"summary\": \"A peaceful evening walk through a park at sunset\", \"key_scenes\": [\"Person entering the park\", \"Walking along tree-lined path\", \"Sunset lighting through trees\", \"Person sitting on bench\"], \"duration\": \"Approximately 2 minutes\"}",
  "finishReason": "stop"
}
```

**达到最大词元数时的响应：**

```
{
  "message": "This video contains multiple scenes showing various activities. The first scene shows...",
  "finishReason": "length"
}
```

------

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


****  

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

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

以下配额适用于输入：


****  

| 输入模态 | 最大值 | 
| --- | --- | 
| 文本 | 77 个代币 | 
| Image | 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` – 如果文本超过限制，则返回错误
+ **默认值：**end
+ **兼容的输入类型：**文本

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

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

请求正文中 `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。

### 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 秒 \$1 20 秒）。

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

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

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

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

设置每个剪辑的最小值（以秒为单位）。
+ **类型：**int
+ **必需**：否
+ **取值参数：**范围：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)— 在中定义的 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 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}")
```

------

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

该TwelveLabs Marengo Embed 3.0模型根据视频、文本、音频或图像输入生成增强的嵌入效果。最新版本提高了相似度搜索、聚类和其他机器学习任务的性能和准确性。
+ 提供商 – TwelveLabs
+ 模型 ID – twelvelabs.marengo-embed-3-0-v1:0

Marengo Embed 3.0 提供了几项关键增强功能：
+ **扩展的视频处理能力**-最多可处理 4 小时的视频和音频内容。文件容量最高可达 6 GB，是先前版本的两倍。这使得它非常适合分析完整的体育赛事、扩展的训练视频和完整的电影制作。
+ **增强的运动分析**-该模型提供了显著的改进。它可以更好地了解游戏动态、玩家动作和事件检测。
+ **全球多语言支持**-将语言功能从 12 种扩展到 36 种语言。这使全球组织能够建立统一的搜索和检索系统，在不同的地区和市场上无缝运行。
+ **多模态搜索精度**-在单个嵌入请求中合并图像和描述性文本。这将视觉相似性与语义理解相结合，从而提供更准确且与上下文相关的搜索结果。
+ **减少嵌入尺寸**-从 1024 减少到 512，这有助于降低存储成本。

TwelveLabs Marengo Embed 3.0 模型支持下表中列出的 Amazon Bedrock 运行时操作。
+ 有关不同 API 方法的使用案例的更多信息，请参阅[了解不同模型推理方法的使用案例不同的推理方法](inference-methods.md)。
+ 有关模型类型的更多信息，请参阅 [Amazon Bedrock 中推理的工作原理推理的工作原理](inference-how.md)。
  + 要查看模型列表 IDs 以及中支持的模型和AWS区域TwelveLabs Marengo Embed 3.0，请在表格中搜索模型[Amazon Bedrock 中支持的根基模型](models-supported.md)。
  + 有关推理配置文件的完整列表 IDs，请参阅[支持推理配置文件的区域和模型](inference-profiles-support.md)。推理配置文件 ID 基于AWS区域。


****  

| API 操作 | 受支持的模型类型 | 输入模式 | 输出模态 | 
| --- | --- | --- | --- | 
|  InvokeModel  |  美国东部（弗吉尼亚北部）-[基础模型](models-supported.md)和[推理配置文件](inference-profiles-support.md) 欧洲（爱尔兰）-[推理概况](inference-profiles-support.md) 亚太地区（首尔）-[基本模型](models-supported.md)  |  文本 Image **注意：**还支持文本和图像交错。  |  嵌入  | 
| StartAsyncInvoke | [基础模型](models-supported.md) |  视频 音频 Image 文本 **注意：**还支持文本和图像交错。  |  嵌入  | 

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

以下配额适用于输入：


****  

| 输入模态 | 最大值 | 
| --- | --- | 
| 文本 | 500 个代币 | 
| Image | 每张图片 5 MB | 
| 视频（S3） | 6 GB，时长 4 小时 | 
| 音频（S3） | 6 GB，时长 4 小时 | 

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

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

## TwelveLabs Marengo Embed 3.0 请求参数
<a name="model-parameters-marengo-3-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",
    "text": {
        "inputText": "string"
    }
}
```

------
#### [ Image ]

```
{
  "inputType": "image",
  "image": {
    "mediaSource": {
      "base64String": "base64-encoded string", // base64String OR s3Location, exactly one
      "s3Location": {
        "uri": "s3://amzn-s3-demo-bucket/folder/dog.jpg",
        "bucketOwner": "123456789012"
      }
    }
  }
}
```

------
#### [ Text & image ]

```
{
  "inputType": "text_image",
  "text_image": {
    "inputText": "man walking a dog",
    "mediaSource": {
      "base64String": "base64-encoded string", // base64String OR s3Location, exactly one
      "s3Location": {
        "uri": "s3://amzn-s3-demo-bucket/folder/dog.jpg",
        "bucketOwner": "123456789012"
      }
    }
  }
}
```

------
#### [ Audio ]

```
{
  "inputType": "audio",
  "audio": {
    "mediaSource": {
      "base64String": "base64-encoded string", // base64String OR s3Location, exactly one
      "s3Location": {
        "uri": "s3://amzn-s3-demo-bucket/audio/a.wav",
        "bucketOwner": "123456789012"
      }
    },
    "startSec": 0,
    "endSec": 6,
    "segmentation": {
      "method": "fixed", 
      "fixed": {
        "durationSec": 6
      }
    },
    "embeddingOption": [
      "audio",
      "transcription"
    ], // optional, default=both
    "embeddingScope": [
      "clip",
      "asset"
    ] // optional, one or both
  }
}
```

------
#### [ Video ]

```
{
  "inputType": "video",
  "video": {
    "mediaSource": {
      "base64String": "base64-encoded string", // base64String OR s3Location, exactly one
      "s3Location": {
        "uri": "s3://amzn-s3-demo-bucket/video/clip.mp4",
        "bucketOwner": "123456789012"
      }
    },
    "startSec": 0,
    "endSec": 6,
    "segmentation": {
      "method": "dynamic", // dynamic OR fixed, exactly one
      "dynamic": {
        "minDurationSec": 4
      }
      "method": "fixed",
      "fixed": {
        "durationSec": 6
      }
    },
    "embeddingOption": [
      "visual",
      "audio", 
      "transcription"
    ], // optional, default=all
    "embeddingScope": [
      "clip",
      "asset"
    ] // optional, one or both
  },
  "inferenceId": "some inference id"
}
```

------

展开以下各个部分，查看有关输入参数的详细信息：

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

嵌入的模态。
+ **类型**：字符串
+ **是否必需**：是
+ **有效值**：`text` \$1 `image` \$1 `text_image` \$1 `audio` \$1 `video`

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

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

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

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

请求正文中 `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。

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

指定要检索的嵌入的类型。
+ **类型**：列表
+ **必需**：否
+ **列表成员的有效值：**
  + `visual`— 视频中的视觉嵌入内容。
  + `audio` – 视频中的音频嵌入。
  + `transcription`— 转录文本的嵌入。
+ **默认值：**
  + 视频：[“视觉”、“音频”、“转录”]
  + 音频：[“音频”，“转录”]
+ **兼容的输入类型：**视频、音频

### 嵌入式作用域
<a name="model-parameters-marengo-3-embeddingScope"></a>

指定要检索的嵌入的范围。
+ **类型**：列表
+ **必需**：否
+ **列表成员的有效值：**
  + `clip`— 返回每个片段的嵌入内容。
  + `asset`— 返回整个资源的嵌入内容。
+ **兼容的输入类型：**视频、音频

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

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

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

处理应结束的时间点（以秒为单位）。
+ **类型**：双精度
+ **必需**：否
+ **最小值：**起始秒 \$1 分段长度
+ **最大值：**媒体持续时间
+ **默认值：**媒体时长
+ **兼容的输入类型：**视频、音频

### 分割
<a name="model-parameters-marengo-3-segmentation"></a>

定义如何将媒体划分为片段以进行嵌入生成。
+ **类型**：对象
+ **必需**：否
+ **兼容的输入类型：**视频、音频

分割对象包含`method`字段和特定于方法的参数：
+ `method`— 要使用的分割方法。有效值：`dynamic` \$1 `fixed`
+ `dynamic`— 对于视频，使用镜头边界检测来动态划分内容。包含：
  + `minDurationSec`— 每个片段的最短持续时间（以秒为单位）。类型：整数。射程：1-5。默认值：4。
+ `fixed`— 将内容分成持续时间相等的片段。包含：
  + `durationSec`— 每个片段的持续时间（以秒为单位）。类型：整数。射程：1-10。默认值：6。

**默认行为**：
+ 视频：使用动态分割和镜头边界检测。
+ 音频：使用固定分段。内容尽可能均匀地分割，片段接近10秒。

### 推断 ID
<a name="model-parameters-marengo-3-inferenceId"></a>

推理请求的唯一标识符。
+ **类型**：字符串
+ **必需**：否

## TwelveLabs Marengo Embed 3.0 响应
<a name="model-parameters-marengo-3-response"></a>

输出嵌入和关联元数据的位置取决于调用方法：
+ InvokeModel — 在响应正文中。
+ StartAsyncInvoke — 在中定义的 S3 存储桶中`s3OutputDataConfig`，在异步调用任务完成后。

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

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

```
{
  "data": {
    "embedding": [
    0.111, 0.234, ...
    ],
    "embeddingOption": ["visual", "audio", "transcription" (for video input) | "audio", "transcription" (for audio input)],
    "embeddingScope": ["asset" | "clip"],
    "startSec": 0,
    "endSec": 4.2
  }
}
```

嵌入以浮点数组的形式返回。

您在何处看到此响应取决于您使用的 API 方法：
+ InvokeModel — 出现在响应正文中。
+ StartAsyncInvoke — 出现在您在请求中指定的 S3 位置。响应返回一个`invocationArn`。您可以使用它来获取有关异步调用的元数据。这包括状态和写入结果的 S3 位置。

展开以下各个部分，查看有关响应参数的详细信息：

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

输入的嵌入向量表示。
+ **类型**：双精度数列表

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

嵌入的类型。
+ **类型**：字符串
+ **可能的值：**
  + visual — 视频中的视觉嵌入内容。
  + 音频-在视频中嵌入音频。
  + 转录-转录文本的嵌入。
+ **兼容的输入类型：**视频、音频

### 嵌入式作用域
<a name="model-parameters-marengo-3-embeddingScope"></a>

指定要检索的嵌入的范围。
+ **类型**：字符串

您可以包含以下一个或多个值：
+ clip：返回每个片段的嵌入内容。
+ asset：返回整个资产的嵌入内容。

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

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

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

片段的末端偏移量。不适用于文本、图像和文本图像嵌入。
+ **类型**：双精度
+ **兼容的输入类型：**视频、音频

## TwelveLabs Marengo Embed 3.0 代码示例
<a name="model-parameters-marengo-3-examples"></a>

此部分介绍如何通过 Python 将 TwelveLabs Marengo Embed 3.0 模型与不同的输入类型结合使用。这些示例演示了如何定义特定于模型的输入和运行模型调用。

**注意**  
InvokeModel 支持文本、图像和带有图像交错输入的文本。对于视频和音频输入，请使用 StartAsyncInvoke。

按以下步骤操作来整合代码：

**1. 定义特定于模型的输入**  
根据输入类型定义特定于模型的输入：

------
#### [ Text ]

```
# Create the model-specific input
model_id = "twelvelabs.marengo-embed-3-0-v1:0"
# Replace the us prefix depending on your region
inference_profile_id = "us.twelvelabs.marengo-embed-3-0-v1:0"

model_input = {
    "inputType": "text",
    "text": {
        "inputText": "man walking a dog"
    }
}
```

------
#### [ Image ]

```
# Create the model-specific input
model_id = "twelvelabs.marengo-embed-3-0-v1:0"
# Replace the us prefix depending on your region
inference_profile_id = "us.twelvelabs.marengo-embed-3-0-v1:0"

model_input = {
    "inputType": "image",
    "image": {
        "mediaSource": {
            "s3Location": {
                "uri": "s3://amzn-s3-demo-bucket/my_image.png",
                "bucketOwner": "123456789012"
            }
        }
    }
}
```

------
#### [ Text & image ]

```
# Create the model-specific input
model_id = "twelvelabs.marengo-embed-3-0-v1:0"
# Replace the us prefix depending on your region
inference_profile_id = "us.twelvelabs.marengo-embed-3-0-v1:0"

model_input = {
    "inputType": "text_image",
    "text_image": {
        "inputText": "man walking a dog",
        "mediaSource": {
            "s3Location": {
                "uri": "s3://amzn-s3-demo-bucket/my_image.jpg",
                "bucketOwner": "123456789012"
            }
        }
    }
}
```

------
#### [ Audio ]

```
# Create the model-specific input
model_id = "twelvelabs.marengo-embed-3-0-v1:0"
# Replace the us prefix depending on your region
inference_profile_id = "us.twelvelabs.marengo-embed-3-0-v1:0"
 
model_input = {
    "inputType": "audio",
    "audio": {
        "mediaSource": {  
            "s3Location": { 
                "uri": "s3://amzn-s3-demo-bucket/my-audio.wav", 
                "bucketOwner": "123456789012" 
            }
        },
        "startSec": 0,
        "endSec": 5,
        "segmentation": {
            "method": "fixed",
            "fixed": {
                "durationSec": 5
            }
        },
        "embeddingScope": ["clip", "asset"],
        "embeddingOption": ["audio"]
    }
}
```

------
#### [ Video ]

```
# Create the model-specific input
model_id = "twelvelabs.marengo-embed-3-0-v1:0"
# Replace the us prefix depending on your region
inference_profile_id = "us.twelvelabs.marengo-embed-3-0-v1:0"
 
model_input = {
    "inputType": "video",
    "video": {
        "mediaSource": {
            "s3Location": {
                "uri": "s3://amzn-s3-demo-bucket/my-video.mp4",
                "bucketOwner": "123456789012"
            }
        },
        "startSec": 10,
        "endSec": 20,
        "segmentation": {
            "method": "fixed",
            "fixed": {
                "durationSec": 5
            }
        },
        "embeddingOption": [
            "visual", 
            "audio"
        ],
        "embeddingScope": [
            "clip",
            "asset"
        ]
    }
}
```

------

**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://amzn-s3-demo-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}")
```

------