Create Embedding Model
Every embedding model takes a credential, a model name, and an optionalParameters object, the same pattern as chat models. Parameters carries dimensions, the output vector size:
Valid
dimensions values differ per model: each model card pins the default via its top-level dimensions field and the allowed values via supported_dimensions (e.g. text-embedding-v4 accepts 2048 / 1536 / 1024 / … / 64). See EmbeddingModelCard.Call Embedding Model
Invoke the model by calling it with a list of inputs. Text-only models acceptlist[str]; multimodal models also accept DataBlock elements:
- Inputs are split into chunks of the model’s batch size (10 for DashScope text, 2048 for OpenAI, 100 for Gemini, 512 for Ollama).
- All chunks are dispatched concurrently via
asyncio.gather. - Each chunk is retried independently up to
max_retriestimes on provider-specific retryable errors. - Results are merged into a single
EmbeddingResponse, preserving input order.
EmbeddingResponse carries:
Multimodal Embedding
Multimodal models (DashScopeEmbeddingModel with qwen3-vl-embedding etc., GeminiEmbeddingModel with gemini-embedding-2) accept DataBlock inputs alongside strings (images as URL or base64, videos as URL):
Multimodal models replace the plain batch-size split with content-aware batching: inputs are greedily packed into batches that respect the model’s per-request limits on total elements, images, and videos (e.g.
qwen3-vl-embedding allows 20 elements / 5 images / 1 video per request, tongyi-embedding-vision-plus allows 20 / 64 / 8). You never need to split inputs yourself.Embedding Cache
Pass anEmbeddingCacheBase implementation through the embedding_cache argument to reuse previously computed vectors. The built-in FileEmbeddingCache stores each result as a .npy file keyed by the SHA-256 hash of the request:
max_file_number or max_cache_size is exceeded, the oldest files are evicted first. To use a different backend (Redis, SQLite, …), subclass EmbeddingCacheBase and implement its four methods: store, retrieve, remove, and clear.
Custom Embedding Provider
Adding an embedding provider follows the same steps as a custom chat provider.Step 1: Link the Credential
Overrideget_embedding_model_class() on your credential (the base implementation returns None, meaning “no embedding support”):
Step 2: Implement the Embedding Model
SubclassEmbeddingModelBase and implement _call_api for a single batch; batching, concurrency, and retry are inherited from the base class. Declare provider-specific transient errors via _get_retryable_exceptions:
EmbeddingModelBase[str] for text-only, EmbeddingModelBase[str | DataBlock] for multimodal, so IDEs surface the correct inputs type to callers.
Step 3: Add Model Cards (optional)
Drop YAML files into a_models/ directory next to your implementation; MyProviderEmbeddingModel.list_models() then picks them up, exactly like chat model cards.
EmbeddingModelCard
EmbeddingModelCard mirrors the general ModelCard for the frontend, with embedding-specific defaults: the output type application/x-embedding marks a model as producing dense vectors.
A typical YAML card (the real card for
text-embedding-v4):
get_embedding_model_class():