Class: RubyAmazonBedrock::PayloadBuilders::Cohere::EmbedBase

Inherits:
Base
  • Object
show all
Defined in:
lib/bedrock_runtime/payload_builders/cohere/embed_base.rb

Overview

Builds and returns a payload hash suitable for the Cohere command model processing. This method constructs a payload with specific parameters like ‘model_id`, `content_type`, `accept`, and a `body` that includes various AI-related settings.

Returns:

  • (Hash)

    The constructed payload containing AI model parameters and settings.

Direct Known Subclasses

EmbedEnglishV3, EmbedMultilingualV3

Instance Method Summary collapse

Methods inherited from Base

#initialize, #type

Constructor Details

This class inherits a constructor from RubyAmazonBedrock::PayloadBuilders::Base

Instance Method Details

#buildHash

Builds and returns a payload suitable for text embedding or search tasks. The method configures the necessary payload structure for processing text input, specifically for embedding or indexing in an AI-driven search system.

Returns:

  • (Hash)

    A hash representing the structured payload for text embedding or search:

    • :model_id [String] Identifier of the AI model that will process the embedding or search task.

    • :content_type [String] Specifies the content type of the payload, typically ‘application/json’.

    • :accept [String] Indicates the MIME type the response should conform to.

    • :body [String] A JSON string that includes the following:

      • :texts [Array<String>] The text(s) to be processed, either a single string or an array of strings.

      • :input_type [String] Specifies the nature of the input, set to ‘search_document’ for search tasks.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bedrock_runtime/payload_builders/cohere/embed_base.rb', line 23

def build
  {
    model_id: model_id,
    content_type: 'application/json',
    accept: '*/*',
    body: {
      texts: [@prompt],
      input_type: parameters[:input_type],
      truncate: parameters[:truncate]
    }.to_json
  }
end

#model_idObject



36
37
38
# File 'lib/bedrock_runtime/payload_builders/cohere/embed_base.rb', line 36

def model_id
  # noop
end

#parametersObject



40
41
42
43
44
45
# File 'lib/bedrock_runtime/payload_builders/cohere/embed_base.rb', line 40

def parameters
  {
    input_type: @options[:input_type] || 'search_document',
    truncate: @options[:truncate] || 'NONE'
  }
end