Skip to main content
This page covers the full workflow of generating embeddings — from building requests to extracting and comparing vectors.

Generating a Single Embedding

The most common path is straightforward. Pass a text string, execute the request, and extract the vector:

Embedding Multiple Texts

You can generate embeddings for multiple texts in a single request, which is significantly more efficient than making separate calls:

Using the Shorthand Method

The with() method lets you set inputs, options, and model in a single call:

The EmbeddingsResponse Object

The get() method returns an EmbeddingsResponse with several methods for accessing results:

Accessing Usage Information

Every response includes token usage data:

Working with Vector Objects

Each embedding in the response is wrapped in a Vector object that provides methods for accessing values and comparing vectors.

Basic Vector Operations

Comparing Vectors

The Vector class supports three distance metrics for comparing embeddings:
You can also use the static methods directly on float arrays:

Finding Similar Documents

The EmbedUtils class provides a convenient findSimilar() method that embeds a query and a set of documents in a single request, then ranks documents by cosine similarity:

Switching Between Providers

The same code works across providers — just change the preset name:

Provider-Specific Options

Different providers support additional options that you can pass through withOptions():

Custom Configuration

When you need full control over the connection parameters, create an EmbeddingsConfig directly:
You can also load configuration from a DSN string: