class VoyageAiGateway implements EmbeddingGateway, RerankingGateway

Traits

Methods

createClient(string $baseUrl, array $headers = [], array $configuredHeaders = [], int|null $timeout = 60, bool $throw = true)

Create an HTTP client with the provider's request options.

string
httpConnection(Provider $provider)

Select a boot-registered connection without retaining dynamic provider names.

client(Provider $provider, int|null $timeout = null)

Get an HTTP client for the Voyage AI API.

string
baseUrl(Provider $provider)

Get the base URL for the Voyage AI API.

bool
usesMultimodalEmbeddingEndpoint(string $model, array $inputs)

Determine if the model or inputs require Voyage AI's multimodal endpoint.

generateMultimodalEmbeddings(EmbeddingProvider $provider, string $model, array $inputs, int $dimensions, int $timeout = 30, array $providerOptions = [])

Generate embeddings for text and image inputs using Voyage AI's multimodal endpoint.

void
validateMultimodalEmbeddingInputSources(array $inputs)

Validate Voyage AI's per-request media source constraint.

string|null
multimodalEmbeddingInputSource(mixed $input)

Get the media source type used by a multimodal embeddings input.

array
mapMultimodalEmbeddingInput(mixed $input)

Map a Hypervel embeddings input to Voyage AI's multimodal input segment.

mixed
withErrorHandling(string $providerName, Closure $callback)

Execute a callback with failoverable error handling.

int|null
retryAfterSeconds(Throwable $exception)

Get the short Retry-After delay of a rate limited or overloaded response, if it has one.

bool
isInsufficientCredits(RequestException $exception)

Determine if the response is a 402, or a 429 insufficient credits or quota error rather than a rate limit.

array
overloadedStatusCodes()

Get the status codes that indicate a provider is transiently unavailable and the request should fail over.

array
insufficientCreditPatterns()

Get the patterns used to detect insufficient credits or quota errors.

array
insufficientCreditCodes()

Get the error codes or types that indicate insufficient credits or quota on a 429 response.

generateEmbeddings(EmbeddingProvider $provider, string $model, array $inputs, int $dimensions, int $timeout = 30, array $providerOptions = [])

Generate embeddings for the given inputs.

rerank(RerankingProvider $provider, string $model, array $documents, string $query, int|null $limit = null, int $timeout = 30, array $providerOptions = [])

Rerank the given documents based on their relevance to the query.

Details

in CreatesClient at line 21
protected PendingRequest createClient(string $baseUrl, array $headers = [], array $configuredHeaders = [], int|null $timeout = 60, bool $throw = true)

Create an HTTP client with the provider's request options.

Parameters

string $baseUrl
array $headers
array $configuredHeaders
int|null $timeout
bool $throw

Return Value

PendingRequest

in CreatesClient at line 43
protected string httpConnection(Provider $provider)

Select a boot-registered connection without retaining dynamic provider names.

Parameters

Provider $provider

Return Value

string

protected PendingRequest client(Provider $provider, int|null $timeout = null)

Get an HTTP client for the Voyage AI API.

Parameters

Provider $provider
int|null $timeout

Return Value

PendingRequest

protected string baseUrl(Provider $provider)

Get the base URL for the Voyage AI API.

Parameters

Provider $provider

Return Value

string

protected bool usesMultimodalEmbeddingEndpoint(string $model, array $inputs)

Determine if the model or inputs require Voyage AI's multimodal endpoint.

Parameters

string $model
array $inputs

Return Value

bool

protected EmbeddingsResponse generateMultimodalEmbeddings(EmbeddingProvider $provider, string $model, array $inputs, int $dimensions, int $timeout = 30, array $providerOptions = [])

Generate embeddings for text and image inputs using Voyage AI's multimodal endpoint.

Parameters

EmbeddingProvider $provider
string $model
array $inputs
int $dimensions
int $timeout
array $providerOptions

Return Value

EmbeddingsResponse

protected void validateMultimodalEmbeddingInputSources(array $inputs)

Validate Voyage AI's per-request media source constraint.

Parameters

array $inputs

Return Value

void

in MapsEmbeddingInputs at line 100
protected string|null multimodalEmbeddingInputSource(mixed $input)

Get the media source type used by a multimodal embeddings input.

Parameters

mixed $input

Return Value

string|null

in MapsEmbeddingInputs at line 114
protected array mapMultimodalEmbeddingInput(mixed $input)

Map a Hypervel embeddings input to Voyage AI's multimodal input segment.

Parameters

mixed $input

Return Value

array

protected mixed withErrorHandling(string $providerName, Closure $callback)

Execute a callback with failoverable error handling.

Parameters

string $providerName
Closure $callback

Return Value

mixed

protected int|null retryAfterSeconds(Throwable $exception)

Get the short Retry-After delay of a rate limited or overloaded response, if it has one.

Parameters

Throwable $exception

Return Value

int|null

protected bool isInsufficientCredits(RequestException $exception)

Determine if the response is a 402, or a 429 insufficient credits or quota error rather than a rate limit.

Parameters

RequestException $exception

Return Value

bool

protected array overloadedStatusCodes()

Get the status codes that indicate a provider is transiently unavailable and the request should fail over.

Return Value

array

protected array insufficientCreditPatterns()

Get the patterns used to detect insufficient credits or quota errors.

Return Value

array

protected array insufficientCreditCodes()

Get the error codes or types that indicate insufficient credits or quota on a 429 response.

Return Value

array

at line 33
EmbeddingsResponse generateEmbeddings(EmbeddingProvider $provider, string $model, array $inputs, int $dimensions, int $timeout = 30, array $providerOptions = [])

Generate embeddings for the given inputs.

Parameters

EmbeddingProvider $provider
string $model
array $inputs
int $dimensions
int $timeout
array $providerOptions

Return Value

EmbeddingsResponse

at line 70
RerankingResponse rerank(RerankingProvider $provider, string $model, array $documents, string $query, int|null $limit = null, int $timeout = 30, array $providerOptions = [])

Rerank the given documents based on their relevance to the query.

Parameters

RerankingProvider $provider
string $model
array $documents
string $query
int|null $limit
int $timeout
array $providerOptions

Return Value

RerankingResponse