Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/phpaisdk/voyageai/llms.txt

Use this file to discover all available pages before exploring further.

Text embeddings turn strings into dense float vectors that capture semantic meaning, enabling similarity search, clustering, and retrieval-augmented generation. The aisdk/voyageai package wires Voyage AI’s text embeddings endpoint into the PHP AI SDK’s portable Generate::embedding() interface, so you can switch providers without rewriting application logic.

Single Document Embedding

Pass a single string to Generate::embedding() when you need a vector for one piece of text.
use AiSdk\Generate;
use AiSdk\VoyageAI;

$result = Generate::embedding('The quick brown fox jumps over the lazy dog')
    ->model(VoyageAI::model('voyage-4-large'))
    ->run();

// float[] — the vector for the input string
$vector = $result->output->vector;

Batch Embedding

Pass an array of strings to embed multiple documents in a single API call. Voyage AI returns one vector per input, in the same order.
use AiSdk\Generate;
use AiSdk\VoyageAI;

$result = Generate::embedding([
        'First document',
        'Second document',
    ])
    ->model(VoyageAI::model('voyage-4-large'))
    ->dimensions(512)
    ->providerOptions('voyageai', [
        'input_type' => 'document',
    ])
    ->run();

$vector  = $result->output->vector;   // float[] — first document's vector
$vectors = $result->embeddings;       // array of all embedding objects

Accessing Results

The EmbeddingResponse returned by ->run() exposes every piece of data the API sends back.
// float[] — vector for the first (or only) document
$firstVector = $result->output->vector;

// All embedding objects, one per input string
$allEmbeddings = $result->embeddings;

// Vector for a specific document by zero-based index
$secondVector = $result->embeddings[1]->vector;

// Token counts reported by Voyage AI
$inputTokens = $result->usage->inputTokens;
$totalTokens = $result->usage->totalTokens;

// Model ID echoed back in the API response
$confirmedModel = $result->providerMetadata['voyageai']['model'];
$result->output->vector always refers to the first embedding object ($result->embeddings[0]->vector), regardless of how many inputs were sent.

Controlling Output Dimensions

Call ->dimensions(int $n) on the builder to request a specific vector length. The SDK maps this to Voyage’s output_dimension field before sending the request.
$result = Generate::embedding(['First document', 'Second document'])
    ->model(VoyageAI::model('voyage-4-large'))
    ->dimensions(256)   // sent as output_dimension=256
    ->run();
Smaller dimensions reduce storage and compute costs at the expense of some recall quality. Not every Voyage model supports custom dimensions — check Voyage AI’s documentation for per-model limits before using this option.
Model IDs are passed to Voyage’s API unchanged. The SDK does not maintain an internal allowlist, so Voyage’s API itself is always the source of truth for which models are available and what dimension ranges they support.

Build docs developers (and LLMs) love