AzureOpenAIEmbeddings Class — langchain Architecture
Architecture documentation for the AzureOpenAIEmbeddings class in azure.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD b39b2417_4449_2d2f_168b_475b9217cf18["AzureOpenAIEmbeddings"] 02ce964e_7ae0_baca_8a6a_784328c5c8a2["OpenAIEmbeddings"] b39b2417_4449_2d2f_168b_475b9217cf18 -->|extends| 02ce964e_7ae0_baca_8a6a_784328c5c8a2 fe99e450_f39e_b29c_2ae7_ae092f3a28f1["azure.py"] b39b2417_4449_2d2f_168b_475b9217cf18 -->|defined in| fe99e450_f39e_b29c_2ae7_ae092f3a28f1 cfd54c5b_d807_5122_ac12_7fb10c9f92ad["validate_environment()"] b39b2417_4449_2d2f_168b_475b9217cf18 -->|method| cfd54c5b_d807_5122_ac12_7fb10c9f92ad 8cf6af83_ed48_711c_2988_f3f77d12397a["_llm_type()"] b39b2417_4449_2d2f_168b_475b9217cf18 -->|method| 8cf6af83_ed48_711c_2988_f3f77d12397a
Relationship Graph
Source Code
libs/partners/openai/langchain_openai/embeddings/azure.py lines 16–230
class AzureOpenAIEmbeddings(OpenAIEmbeddings): # type: ignore[override]
"""AzureOpenAI embedding model integration.
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.
You'll need to have an Azure OpenAI instance deployed.
You can deploy a version on Azure Portal following this
[guide](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource?pivots=web-portal).
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.
```bash
pip install -U langchain_openai
# Set up your environment variables (or pass them directly to the model)
export AZURE_OPENAI_API_KEY="your-api-key"
export AZURE_OPENAI_ENDPOINT="https://<your-endpoint>.openai.azure.com/"
export AZURE_OPENAI_API_VERSION="2024-02-01"
```
Key init args — completion params:
model:
Name of `AzureOpenAI` model to use.
dimensions:
Number of dimensions for the embeddings. Can be specified only if the
underlying model supports it.
See full list of supported init args and their descriptions in the params section.
Instantiate:
```python
from langchain_openai import AzureOpenAIEmbeddings
embeddings = AzureOpenAIEmbeddings(
model="text-embedding-3-large"
# dimensions: int | None = 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
)
```
Embed single text:
```python
input_text = "The meaning of life is 42"
vector = embed.embed_query(input_text)
print(vector[:3])
```
```python
[-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
```
Embed multiple texts:
```python
input_texts = ["Document 1...", "Document 2..."]
vectors = embed.embed_documents(input_texts)
print(len(vectors))
# The first 3 coordinates for the first vector
print(vectors[0][:3])
```
```python
2
[-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
```
Async:
```python
vector = await embed.aembed_query(input_text)
print(vector[:3])
# multiple:
# await embed.aembed_documents(input_texts)
```
```python
[-0.009100092574954033, 0.005071679595857859, -0.0029193938244134188]
```
""" # noqa: E501
Extends
Source
Frequently Asked Questions
What is the AzureOpenAIEmbeddings class?
AzureOpenAIEmbeddings is a class in the langchain codebase, defined in libs/partners/openai/langchain_openai/embeddings/azure.py.
Where is AzureOpenAIEmbeddings defined?
AzureOpenAIEmbeddings is defined in libs/partners/openai/langchain_openai/embeddings/azure.py at line 16.
What does AzureOpenAIEmbeddings extend?
AzureOpenAIEmbeddings extends OpenAIEmbeddings.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free