Initialize an embeddings model from a model name and optional provider.
Must have the integration package corresponding to the model provider installed.
init_embeddings(
model: str,
*,
provider: str | None = None,
**kwargs: Any = {}
) -> Embeddings | Runnable[Any, list[float]]# Using a model string
model = init_embeddings("openai:text-embedding-3-small")
model.embed_query("Hello, world!")
# Using explicit provider
model = init_embeddings(model="text-embedding-3-small", provider="openai")
model.embed_documents(["Hello, world!", "Goodbye, world!"])
# With additional parameters
model = init_embeddings("openai:text-embedding-3-small", api_key="sk-...")| Name | Type | Description |
|---|---|---|
model* | str | Name of the model to use. Can be either:
See supported providers under the |
provider | str | None | Default: NoneOptional explicit provider name. If not specified, will attempt to
parse from the model string in the Supported providers:
|
**kwargs | Any | Default: {}Additional model-specific parameters passed to the embedding model. These vary by provider, see the provider-specific documentation for details. |