init_embeddings#
- langchain.embeddings.base.init_embeddings(model: str, *, provider: str | None = None, **kwargs: Any) Embeddings | Runnable[Any, List[float]] [source]#
Beta
This feature is in beta. It is actively being worked on, so the API may change.
Initialize an embeddings model from a model name and optional provider.
Note: Must have the integration package corresponding to the model provider installed.
- Parameters:
model (str) β Name of the model to use. Can be either: - A model string like βopenai:text-embedding-3-smallβ - Just the model name if provider is specified
provider (str | None) β
Optional explicit provider name. If not specified, will attempt to parse from the model string. Supported providers and their required packages:
{_get_provider_list()}
**kwargs (Any) β Additional model-specific parameters passed to the embedding model. These vary by provider, see the provider-specific documentation for details.
- Returns:
An Embeddings instance that can generate embeddings for text.
- Raises:
ValueError β If the model provider is not supported or cannot be determined
ImportError β If the required provider package is not installed
- Return type:
Embeddings | Runnable[Any, List[float]]
Example Usage
# 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-..." )
Added in version 0.3.9.