AWS Bedrock Provider

View Source

Embedding generation using AWS Bedrock's embedding API. Provides access to Amazon Titan and Cohere embedding models through AWS infrastructure.

Requirements

  • AWS account with Bedrock access
  • Model access enabled in Bedrock console
  • Authentication via API key (ABSK) or IAM credentials

Configuration

Uses AWS Bedrock API Key (ABSK format, available since July 2025):

{ok, State} = barrel_embed:init(#{
    embedder => {bedrock, #{
        api_key => <<"ABSK...">>,                % or use env var
        region => <<"us-east-1">>,
        model => <<"amazon.titan-embed-text-v2:0">>
    }}
}).

Option 2: IAM Credentials

Uses AWS access keys with SigV4 signing:

{ok, State} = barrel_embed:init(#{
    embedder => {bedrock, #{
        access_key_id => <<"AKIA...">>,
        secret_access_key => <<"...">>,
        session_token => <<"...">>,              % optional, for temporary credentials
        region => <<"us-east-1">>,
        model => <<"amazon.titan-embed-text-v2:0">>
    }}
}).

Options

OptionTypeDefaultDescription
api_keybinaryBEDROCK_API_KEY env varAPI key (ABSK format)
access_key_idbinaryAWS_ACCESS_KEY_ID env varIAM access key
secret_access_keybinaryAWS_SECRET_ACCESS_KEY env varIAM secret key
session_tokenbinaryAWS_SESSION_TOKEN env varSession token (optional)
regionbinary<<"us-east-1">>AWS region
modelbinary<<"amazon.titan-embed-text-v2:0">>Model ID

Using Environment Variables

# Option 1: API key
export BEDROCK_API_KEY=ABSK...

# Option 2: IAM credentials
export AWS_ACCESS_KEY_ID=AKIA...
export AWS_SECRET_ACCESS_KEY=...
export AWS_REGION=us-east-1
{ok, State} = barrel_embed:init(#{
    embedder => {bedrock, #{
        model => <<"amazon.titan-embed-text-v2:0">>
    }}
}).

Supported Models

Enable model access in AWS Bedrock console first:

ModelDimensionsNotes
amazon.titan-embed-text-v2:01024Default, Amazon Titan
amazon.titan-embed-text-v11536Legacy Titan
cohere.embed-english-v31024Cohere English
cohere.embed-multilingual-v31024Cohere multilingual

Setup Steps

  1. Enable Model Access

    • Go to AWS Console -> Bedrock
    • Click "Model access"
    • Request access for embedding models
  2. Get Credentials

    For API key:

    • Go to Bedrock -> API keys
    • Create a new API key (ABSK format)

    For IAM:

    • Create IAM user with Bedrock permissions
    • Generate access keys

Example

%% Initialize with API key
{ok, State} = barrel_embed:init(#{
    embedder => {bedrock, #{
        api_key => <<"ABSK...">>,
        region => <<"us-east-1">>,
        model => <<"amazon.titan-embed-text-v2:0">>
    }}
}).

%% Generate embeddings
{ok, Vec} = barrel_embed:embed(<<"Machine learning is fascinating">>, State).

%% Batch (processed sequentially - Bedrock doesn't support native batch)
{ok, Vecs} = barrel_embed:embed_batch([
    <<"Document about AI">>,
    <<"Document about databases">>,
    <<"Document about networking">>
], State).

Regions

Bedrock is available in these regions:

  • us-east-1 (N. Virginia) - Most models
  • us-west-2 (Oregon)
  • eu-central-1 (Frankfurt)
  • eu-west-1 (Ireland)
  • ap-northeast-1 (Tokyo)

Why AWS Bedrock?

  • AWS infrastructure (VPC, IAM, CloudWatch)
  • Multiple model providers (Titan, Cohere) through one API
  • Pay-per-use pricing
  • Enterprise compliance (SOC, HIPAA, FedRAMP)

Pricing

See aws.amazon.com/bedrock/pricing for current rates.