Initialize an embeddings model from a model name and optional provider.
Must have the integration package corresponding to the model provider installed.
# 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 of the model to use.
Can be either:
"openai:text-embedding-3-small"See supported providers under the provider arg description.
Optional explicit provider name. If not specified, will attempt to
parse from the model string in the model arg.
Supported providers:
openai -> langchain-openaiazure_ai -> langchain-azure-aiazure_openai -> langchain-openaibedrock -> langchain-awscohere -> langchain-coheregoogle_genai -> langchain-google-genaigoogle_vertexai -> langchain-google-vertexaihuggingface -> langchain-huggingfacemistralai -> langchain-mistralaiollama -> langchain-ollamaAdditional model-specific parameters passed to the embedding model. These vary by provider, see the provider-specific documentation for details.