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 个令牌
图像 5MB
视频(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 秒的剪辑将被划分为 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 – 视频中的音频嵌入。

  • 兼容的输入类型:视频

剪辑的起始偏移量。

  • 类型:双精度

  • 兼容的输入类型:视频、音频

剪辑的结束偏移量(以秒为单位)。

  • 类型:双精度

  • 兼容的输入类型:视频、音频

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