Skip to main content
Generate text embeddings with AI SDK and native fallback providers.

Quick Start

1

Simple Usage

EmbeddingAgent class

EmbeddingAgent wraps the embedding functions in an agent with similarity helpers.

EmbeddingAgentConfig

EmbeddingConfig

EmbeddingAgent no longer defaults dimensions to 1536. Code that relied on a fixed 1536 dimension for a non-OpenAI model must now pass dimensions: 1536 explicitly.
embed() and embedMany() never fall back to fake vectors — a provider failure throws. embedMany() makes one batched provider call, not N sequential calls.

Direct Embedding API

For more control, use the embedding functions directly:
The dimensions?: number option is forwarded to OpenAI as dimensions and to the AI SDK as providerOptions.openai.dimensions. Other providers ignore it today. Omit it to use the model’s native size.

Sync vs. Async

Embeddings need a network call, so the sync API cannot produce real vectors — the async API does. The sync embed(...) and embeddings(...) functions from praisonai throw — they cannot make a network call. The error names the async replacement:
For batches:
getDimensions(model) stays synchronous — it is a lookup, no network — so callers who only need the dimension size do not await:
aembed(...) and aembeddings(...) delegate to the real network-backed embedder in praisonai/llm/embeddings (AI SDK preferred, native OpenAI fallback). The returned dimensions is the real vector length, not a lookup:

Embedding Models

OpenAI Models

Google Models

Cohere Models

Integration with Knowledge Base

Use embeddings with Knowledge for semantic search:
Passing embeddingProvider in the Knowledge config is what turns on vector similarity in the in-process store. Without it, search falls back to keyword overlap.

Integration with Memory

Use embeddings for semantic memory search:

Custom providers work for both chat and embeddings

A provider registered through the Provider Registry now applies to embeddings as well as chat. As of PraisonAI PR #4874, embed(...), embedMany(...), and agent.embed(...) resolve their provider through the same createAISDKProvider(...) path chat has always used. Previously a registerCustomProvider('openai', ...) call took effect for a chat completion and was silently ignored for an embedding of the same provider.

Embedding provider aliases

These provider names resolve through the AI SDK embedding path:

Backend Selection

PraisonAI automatically selects the best backend:
  1. AI SDK (preferred): When ai package is installed
  2. Native: Falls back to direct OpenAI client
For the AI SDK backend, the provider package is loaded through a computed specifier (await import(providerInfo.package)), the same registry chat uses. A bundler cannot discover this at build time — that is deliberate: the provider package is a host-supplied optional peer dependency. In a webview or phone build, only native works for providers whose package the host cannot resolve.

Force Backend

Environment Variable

Similarity Functions

Built-in similarity functions for comparing embeddings:

Performance Tips

  1. Batch embeddings: Use embedMany for multiple texts
  2. Cache embeddings: Store embeddings to avoid re-computation
  3. Choose model wisely: text-embedding-3-small is fast and cheap

Error Handling

Unavailable provider packages surface one of two messages:
  • Cohere keeps its exact wording — Cohere provider not installed. Install with: npm install @ai-sdk/cohere — because @ai-sdk/cohere is the one embedding provider the SDK does not itself depend on.
  • Any other provider surfaces the registry’s generic MISSING_DEPENDENCY message: AI SDK provider package '<package>' is not installed. Install it with: npm install <package>.

TypeScript Types

Embeddings CLI

Embeddings CLI overview

Knowledge Base

Knowledge Base overview

Memory System

Semantic memory with real embeddings by default