AzureOpenAIEmbeddings
This will help you get started with AzureOpenAI embedding models using LangChain. For detailed documentation on AzureOpenAIEmbeddings
features and configuration options, please refer to the API reference.
Overview
Integration details
Provider | Package |
---|---|
AzureOpenAI | langchain-openai |
Setup
To access AzureOpenAI embedding models you'll need to create an Azure account, get an API key, and install the langchain-openai
integration package.
Credentials
You’ll need to have an Azure OpenAI instance deployed. You can deploy a version on Azure Portal following this guide.
Once you have your instance running, make sure you have the name of your instance and key. You can find the key in the Azure Portal, under the “Keys and Endpoint” section of your instance.
AZURE_OPENAI_ENDPOINT=<YOUR API ENDPOINT>
AZURE_OPENAI_API_KEY=<YOUR_KEY>
AZURE_OPENAI_API_VERSION="2024-02-01"
import getpass
import os
if not os.getenv("AZURE_OPENAI_API_KEY"):
os.environ["AZURE_OPENAI_API_KEY"] = getpass.getpass(
"Enter your AzureOpenAI API key: "
)
To enable automated tracing of your model calls, set your LangSmith API key:
# os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
Installation
The LangChain AzureOpenAI integration lives in the langchain-openai
package:
%pip install -qU langchain-openai
Instantiation
Now we can instantiate our model object and generate chat completions:
from langchain_openai import AzureOpenAIEmbeddings
embeddings = AzureOpenAIEmbeddings(
model="text-embedding-3-large",
# dimensions: Optional[int] = None, # Can specify dimensions with new text-embedding-3 models
# azure_endpoint="https://<your-endpoint>.openai.azure.com/", If not provided, will read env variable AZURE_OPENAI_ENDPOINT
# api_key=... # Can provide an API key directly. If missing read env variable AZURE_OPENAI_API_KEY
# openai_api_version=..., # If not provided, will read env variable AZURE_OPENAI_API_VERSION
)