Quick Start
1
Simple Usage
EmbeddingAgent class
EmbeddingAgent wraps the embedding functions in an agent with similarity helpers.
EmbeddingAgentConfig
EmbeddingConfig
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: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 syncembed(...) and embeddings(...) functions from praisonai throw — they cannot make a network call. The error names the async replacement:
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 withKnowledge for semantic search:
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:- AI SDK (preferred): When
aipackage is installed - Native: Falls back to direct OpenAI client
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
- Batch embeddings: Use
embedManyfor multiple texts - Cache embeddings: Store embeddings to avoid re-computation
- Choose model wisely:
text-embedding-3-smallis fast and cheap
Error Handling
- Cohere keeps its exact wording —
Cohere provider not installed. Install with: npm install @ai-sdk/cohere— because@ai-sdk/cohereis the one embedding provider the SDK does not itself depend on. - Any other provider surfaces the registry’s generic
MISSING_DEPENDENCYmessage:AI SDK provider package '<package>' is not installed. Install it with: npm install <package>.
TypeScript Types
Related
Embeddings CLI
Embeddings CLI overview
Knowledge Base
Knowledge Base overview
Memory System
Semantic memory with real embeddings by default

