Skip to main content
Embeddings convert text into numerical vectors that capture semantic meaning, enabling similarity search, clustering, and classification.

Basic Usage

Generate embeddings for text:

Single vs Batch Embedding

Embed single or multiple texts:

Embedding Response

The embed() function returns an EmbedResult:

Configuring Dimensions

Some models support custom dimensions:
Not all embedding models support custom dimensions. Check your provider’s documentation.
Calculate similarity between vectors:

Semantic Search Example

Build a simple semantic search system:

Clustering Documents

Group similar documents together:

Using Different Providers

Integration with Vector Databases

Store embeddings in vector databases:

Best Practices

Process multiple texts in a single request:
Embeddings are deterministic - cache them:
Pre-normalize vectors for faster similarity:
Split long texts into chunks:

Next Steps

Chat Completion

Generate text responses

Structured Outputs

Get type-safe JSON responses

Tool Calling

Use embeddings in tool functions

Multi-Modal

Work with images and files