Google Vertex AI Provider

View Source

Embedding generation using Google Vertex AI's embedding API. Provides access to Google's embedding models including the Gecko family.

Requirements

  • Google Cloud project with Vertex AI API enabled
  • Authentication via access token or API key

Configuration

Get a token with gcloud auth print-access-token:

{ok, State} = barrel_embed:init(#{
    embedder => {vertex, #{
        access_token => <<"ya29...">>,           % or use env var
        project => <<"my-project">>,
        region => <<"us-central1">>,
        model => <<"text-embedding-004">>
    }}
}).

Option 2: API Key

{ok, State} = barrel_embed:init(#{
    embedder => {vertex, #{
        api_key => <<"...">>,                    % or use env var
        project => <<"my-project">>,
        region => <<"us-central1">>,
        model => <<"text-embedding-004">>
    }}
}).

Options

OptionTypeDefaultDescription
access_tokenbinaryGOOGLE_ACCESS_TOKEN env varOAuth access token
api_keybinaryGOOGLE_API_KEY env varAPI key
projectbinaryGOOGLE_CLOUD_PROJECT env varGCP project ID
regionbinary<<"us-central1">>GCP region
modelbinary<<"text-embedding-004">>Model name

Using Environment Variables

# Get access token
export GOOGLE_ACCESS_TOKEN=$(gcloud auth print-access-token)
export GOOGLE_CLOUD_PROJECT=my-project
{ok, State} = barrel_embed:init(#{
    embedder => {vertex, #{}}
}).

Supported Models

ModelDimensionsNotes
text-embedding-004768Default, latest
text-embedding-005768Newest
textembedding-gecko@001768Legacy
textembedding-gecko@003768Legacy
textembedding-gecko-multilingual@001768Multilingual legacy
text-multilingual-embedding-002768Multilingual

Setup Steps

  1. Enable Vertex AI API

    • Go to GCP Console
    • Enable "Vertex AI API"
  2. Get Authentication

    For development (access token):

    gcloud auth login
    gcloud auth print-access-token
    

    For production (service account):

    • Create service account with Vertex AI User role
    • Download JSON key
    • Use GOOGLE_APPLICATION_CREDENTIALS
  3. Note Project ID

    gcloud config get-value project
    

Example

%% Initialize
{ok, State} = barrel_embed:init(#{
    embedder => {vertex, #{
        access_token => <<"ya29...">>,
        project => <<"my-project">>,
        region => <<"us-central1">>,
        model => <<"text-embedding-004">>
    }}
}).

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

%% Batch
{ok, Vecs} = barrel_embed:embed_batch([
    <<"Document about AI">>,
    <<"Document about databases">>,
    <<"Document about networking">>
], State).

Regions

Vertex AI is available in many regions. Common choices:

  • us-central1 (Iowa) - Default
  • us-east1 (South Carolina)
  • europe-west1 (Belgium)
  • asia-northeast1 (Tokyo)

Access Token Refresh

Access tokens expire after 1 hour. For long-running applications:

  1. Use service account authentication
  2. Or refresh token periodically:
%% Refresh token
NewToken = os:cmd("gcloud auth print-access-token"),
{ok, NewState} = barrel_embed:init(#{
    embedder => {vertex, #{
        access_token => list_to_binary(string:trim(NewToken)),
        project => <<"my-project">>
    }}
}).

Why Vertex AI?

  • Google's latest embedding models
  • Tight integration with GCP services
  • BigQuery, Cloud Storage integration
  • Enterprise security (VPC-SC, CMEK)

Pricing

See cloud.google.com/vertex-ai/pricing for current rates.