Cookie の設定を選択する

当社は、当社のサイトおよびサービスを提供するために必要な必須 Cookie および類似のツールを使用しています。当社は、パフォーマンス Cookie を使用して匿名の統計情報を収集することで、お客様が当社のサイトをどのように利用しているかを把握し、改善に役立てています。必須 Cookie は無効化できませんが、[カスタマイズ] または [拒否] をクリックしてパフォーマンス Cookie を拒否することはできます。

お客様が同意した場合、AWS および承認された第三者は、Cookie を使用して便利なサイト機能を提供したり、お客様の選択を記憶したり、関連する広告を含む関連コンテンツを表示したりします。すべての必須ではない Cookie を受け入れるか拒否するには、[受け入れる] または [拒否] をクリックしてください。より詳細な選択を行うには、[カスタマイズ] をクリックしてください。

Cohere Embed モデル

フォーカスモード
Cohere Embed モデル - Amazon Bedrock

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

InvokeModel を使用してEmbed モデルに推論リクエストを行うには、使用するモデルのモデル ID が必要です。モデル ID を取得するには、「Amazon Bedrock でサポートされている基盤モデル」を参照してください。

注記

Amazon Bedrock は Cohere Embed モデルからのストリーミングレスポンスをサポートしていません。

リクエストとレスポンス

Request

Cohere Embed モデルには次の推論パラメータがあります。

{ "input_type": "search_document|search_query|classification|clustering|image", "texts":[string], "images":[image_base64_image_uri] "truncate": "NONE|START|END", "embedding_types": embedding_types }

必須パラメータを以下に示します。

  • texts – 埋め込むモデルの文字列の配列。最適なパフォーマンスを得るには、各テキストの長さを 512 トークン未満に減らすことをお勧めします。1 トークンは約 4 文字です。

    以下は、呼び出しおよび文字あたりのテキスト数の制限です。

    呼び出しあたりのテキスト

    最小値 最大値

    0 テキスト

    96 テキスト

    文字

    最小値 最大値

    0 文字

    2,048 文字

  • input_type – 特殊なトークンを先頭に付加して、タイプ同士を区別します。検索と取得の間でタイプを混在させる場合を除いて、異なるタイプを混在させないでください。そのような場合、search_document タイプにはコーパスを、search_query タイプには埋め込みクエリを埋め込みます。

    • search_document - 検索のユースケースで、ベクトルデータベースに保存する埋め込み用のドキュメントをエンコードするときに、search_document を使用します。

    • search_query - ベクトル DB にクエリを実行して関連ドキュメントを検索する場合に search_query を使用します。

    • classification - 埋め込みをテキスト分類子への入力として使用する場合に classification を使用します。

    • clustering - 埋め込みをクラスター化する場合に clustering を使用します。

    • images – これはイメージの配列です。

      • 埋め込むモデルのイメージデータ URIs の配列。呼び出しあたりのイメージの最大数は 1 です (つまり、モデルは 1 つのイメージ入力のみをサポートします)。

      • イメージは有効なデータ URI である必要があります。イメージは、image/jpeg 形式または image/png 形式で、最大サイズは 5MB である必要があります。

      • 「イメージ」または「テキスト」のいずれかを指定する必要があります。

オプションのパラメータを以下に示します。

  • truncate – トークンの最大長を超える入力を API がどのように処理するかを指定します。以下のいずれかを使用します。

    • NONE - (デフォルト) 入力が入力トークンの最大長を超えるとエラーを返します。

    • START - 入力の先頭部分を切り捨てます。

    • END - 入力の末尾部分を切り捨てます。

    START または END を指定すると、入力の長さがモデルの入力トークンの最大長とまったく同じになるまで、モデルが入力内容を切り捨てます。

  • embedding_types — 返したい埋め込みのタイプを指定します。オプションとデフォルトは、None で、Embed Floats レスポンスタイプを返します。タイプは次のいずれかになります。

    • float – この値を使用して、デフォルトのフロート埋め込みを返します。

    • int8 – この値を使用して、署名付き int8 埋め込みを返します。

    • uint8 – この値を使用して、署名なし int8 埋め込みを返します。

    • binary – この値を使用して、署名付きバイナリ埋め込みを返します。

    • ubinary – この値を使用して、署名なしバイナリ埋め込みを返します。

詳細については、「Cohere ドキュメント」の https://docs.cohere.com/reference/embed を参照してください。

Response

InvokeModel を呼び出した場合の body レスポンスを以下に示します。

{ "embeddings": [ [ array of 1024 floats. ] ], "id": string, "response_type" : "embeddings_floats, "texts": [string], "images": [image_description] }

body レスポンスに指定できるフィールドについて説明します。

  • id - レスポンスの識別子。

  • response_type – レスポンスタイプ。この値は常に embeddings_floats です。

  • embeddings - 埋め込みの配列。各埋め込みは 1,024 個の要素から成る、浮動小数点数の配列です。embeddings 配列の長さは 元の texts 配列の長さと同じになります。

  • texts - 埋め込みが返されたテキストエントリから成る配列。

  • images – 各イメージ入力の説明の配列。

    image_descriptionimage_description は、次の形式です。

    { "width": long, "height": long, "format": string, "bit_depth": long }

    イメージを入力として使用した場合、“texts”レスポンスフィールドは空の配列になります。vice-versa は true ではありません (つまり、テキストが使用されている場合、 はレスポンスに含まれ“images”ません)

詳細については、https://docs.cohere.com/reference/embed を参照してください。

Cohere Embed モデルには次の推論パラメータがあります。

{ "input_type": "search_document|search_query|classification|clustering|image", "texts":[string], "images":[image_base64_image_uri] "truncate": "NONE|START|END", "embedding_types": embedding_types }

必須パラメータを以下に示します。

  • texts – 埋め込むモデルの文字列の配列。最適なパフォーマンスを得るには、各テキストの長さを 512 トークン未満に減らすことをお勧めします。1 トークンは約 4 文字です。

    以下は、呼び出しおよび文字あたりのテキスト数の制限です。

    呼び出しあたりのテキスト

    最小値 最大値

    0 テキスト

    96 テキスト

    文字

    最小値 最大値

    0 文字

    2,048 文字

  • input_type – 特殊なトークンを先頭に付加して、タイプ同士を区別します。検索と取得の間でタイプを混在させる場合を除いて、異なるタイプを混在させないでください。そのような場合、search_document タイプにはコーパスを、search_query タイプには埋め込みクエリを埋め込みます。

    • search_document - 検索のユースケースで、ベクトルデータベースに保存する埋め込み用のドキュメントをエンコードするときに、search_document を使用します。

    • search_query - ベクトル DB にクエリを実行して関連ドキュメントを検索する場合に search_query を使用します。

    • classification - 埋め込みをテキスト分類子への入力として使用する場合に classification を使用します。

    • clustering - 埋め込みをクラスター化する場合に clustering を使用します。

    • images – これはイメージの配列です。

      • 埋め込むモデルのイメージデータ URIs の配列。呼び出しあたりのイメージの最大数は 1 です (つまり、モデルは 1 つのイメージ入力のみをサポートします)。

      • イメージは有効なデータ URI である必要があります。イメージは、image/jpeg 形式または image/png 形式で、最大サイズは 5MB である必要があります。

      • 「イメージ」または「テキスト」のいずれかを指定する必要があります。

オプションのパラメータを以下に示します。

  • truncate – トークンの最大長を超える入力を API がどのように処理するかを指定します。以下のいずれかを使用します。

    • NONE - (デフォルト) 入力が入力トークンの最大長を超えるとエラーを返します。

    • START - 入力の先頭部分を切り捨てます。

    • END - 入力の末尾部分を切り捨てます。

    START または END を指定すると、入力の長さがモデルの入力トークンの最大長とまったく同じになるまで、モデルが入力内容を切り捨てます。

  • embedding_types — 返したい埋め込みのタイプを指定します。オプションとデフォルトは、None で、Embed Floats レスポンスタイプを返します。タイプは次のいずれかになります。

    • float – この値を使用して、デフォルトのフロート埋め込みを返します。

    • int8 – この値を使用して、署名付き int8 埋め込みを返します。

    • uint8 – この値を使用して、署名なし int8 埋め込みを返します。

    • binary – この値を使用して、署名付きバイナリ埋め込みを返します。

    • ubinary – この値を使用して、署名なしバイナリ埋め込みを返します。

詳細については、「Cohere ドキュメント」の https://docs.cohere.com/reference/embed を参照してください。

コード例

この例は、Cohere Embed English モデルを呼び出す方法を示しています。

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Shows how to generate text embeddings using the Cohere Embed English model. """ import json import logging import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) def generate_text_embeddings(model_id, body, region_name): """ Generate text embedding by using the Cohere Embed model. Args: model_id (str): The model ID to use. body (str) : The reqest body to use. region_name (str): The AWS region to invoke the model on Returns: dict: The response from the model. """ logger.info("Generating text embeddings with the Cohere Embed model %s", model_id) accept = '*/*' content_type = 'application/json' bedrock = boto3.client(service_name='bedrock-runtime', region_name=region_name) response = bedrock.invoke_model( body=body, modelId=model_id, accept=accept, contentType=content_type ) logger.info("Successfully generated embeddings with Cohere model %s", model_id) return response def main(): """ Entrypoint for Cohere Embed example. """ logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") region_name = 'us-east-1' model_id = 'cohere.embed-english-v3' text1 = "hello world" text2 = "this is a test" input_type = "search_document" embedding_types = ["int8", "float"] try: body = json.dumps({ "texts": [ text1, text2], "input_type": input_type, "embedding_types": embedding_types }) response = generate_text_embeddings(model_id=model_id, body=body, region_name=region_name) response_body = json.loads(response.get('body').read()) print(f"ID: {response_body.get('id')}") print(f"Response type: {response_body.get('response_type')}") print("Embeddings") embeddings = response_body.get('embeddings') for i, embedding_type in enumerate(embeddings): print(f"\t{embedding_type} Embeddings:") print(f"\t{embeddings[embedding_type]}") print("Texts") for i, text in enumerate(response_body.get('texts')): print(f"\tText {i}: {text}") except ClientError as err: message = err.response["Error"]["Message"] logger.error("A client error occurred: %s", message) print("A client error occured: " + format(message)) else: print( f"Finished generating text embeddings with Cohere model {model_id}.") if __name__ == "__main__": main()

イメージ入力

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Shows how to generate image embeddings using the Cohere Embed English model. """ import json import logging import boto3 import base64 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) def get_base64_image_uri(image_file_path: str, image_mime_type: str): with open(image_file_path, "rb") as image_file: image_bytes = image_file.read() base64_image = base64.b64encode(image_bytes).decode("utf-8") return f"data:{image_mime_type};base64,{base64_image}" def generate_image_embeddings(model_id, body, region_name): """ Generate image embedding by using the Cohere Embed model. Args: model_id (str): The model ID to use. body (str) : The reqest body to use. region_name (str): The AWS region to invoke the model on Returns: dict: The response from the model. """ logger.info("Generating image embeddings with the Cohere Embed model %s", model_id) accept = '*/*' content_type = 'application/json' bedrock = boto3.client(service_name='bedrock-runtime', region_name=region_name) response = bedrock.invoke_model( body=body, modelId=model_id, accept=accept, contentType=content_type ) logger.info("Successfully generated embeddings with Cohere model %s", model_id) return response def main(): """ Entrypoint for Cohere Embed example. """ logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") region_name = 'us-east-1' image_file_path = "image.jpg" image_mime_type = "image/jpg" model_id = 'cohere.embed-english-v3' input_type = "image" images = [get_base64_image_uri(image_file_path, image_mime_type)] embedding_types = ["int8", "float"] try: body = json.dumps({ "images": images, "input_type": input_type, "embedding_types": embedding_types }) response = generate_image_embeddings(model_id=model_id, body=body, region_name=region_name) response_body = json.loads(response.get('body').read()) print(f"ID: {response_body.get('id')}") print(f"Response type: {response_body.get('response_type')}") print("Embeddings") embeddings = response_body.get('embeddings') for i, embedding_type in enumerate(embeddings): print(f"\t{embedding_type} Embeddings:") print(f"\t{embeddings[embedding_type]}") print("Texts") for i, text in enumerate(response_body.get('texts')): print(f"\tText {i}: {text}") except ClientError as err: message = err.response["Error"]["Message"] logger.error("A client error occurred: %s", message) print("A client error occured: " + format(message)) else: print( f"Finished generating text embeddings with Cohere model {model_id}.") if __name__ == "__main__": main()
プライバシーサイト規約Cookie の設定
© 2025, Amazon Web Services, Inc. or its affiliates.All rights reserved.