DS DevShelfHub Projects · AI tools
Tutorials / LangChain / Reference / Classes / AzureOpenAIEmbeddings
Embeddings langchain-openai Intermediate

AzureOpenAIEmbeddings: Reference Guide

By DevShelfHub

Use Azure-hosted OpenAI embeddings.

What is AzureOpenAIEmbeddings?

AzureOpenAIEmbeddings is the LangChain wrapper for OpenAI embedding models served through Microsoft Azure OpenAI rather than OpenAI directly. The vectors it returns are identical in quality to OpenAIEmbeddings — it is the same text-embedding-3-small, text-embedding-3-large, and text-embedding-ada-002 models underneath — but requests are routed to your Azure resource, billed through your Azure subscription, and kept inside whatever region and network boundary your compliance team requires.

The key difference from the standard class is configuration. Azure addresses a named deployment, not a model: you create a deployment in the Azure portal, then pass its name through azure_deployment (or the legacy deployment_id), set azure_endpoint to your resource URL, and pin api_version to a dated value such as 2024-02-01. Authentication uses AZURE_OPENAI_API_KEY and AZURE_OPENAI_ENDPOINT environment variables, or an Azure AD token provider for keyless auth. Forgetting any one of endpoint, deployment, or api_version is the most common setup failure.

At the API surface it exposes the same embed_query and embed_documents methods as every other LangChain embeddings class, so it drops into a Chroma, Pinecone, or Qdrant retriever without code changes. embed_documents batches internally; for large corpora tune chunk_size to stay under your deployment token-per-minute quota, and set dimensions on the v3 models if you want shorter vectors to save storage. Crucially, the embedding model and deployment you index with must match the one you query with — mixing models silently corrupts similarity scores.

When to Use

You're on Azure or need Azure's enterprise features. Use AzureOpenAIEmbeddings for Azure deployments.

Use Cases

  • Azure deployments
  • Enterprise compliance
  • Private networks
  • Multi-region
  • Azure managed services
  • Regulatory compliance

Key Features

  • Azure-hosted
  • Private access
  • Enterprise features
  • Same models
  • Regional deployment
  • Managed scaling

When NOT to Use

For simple projects not on Azure.

Notes

Deployment name, not model name

Azure addresses a deployment you created in the portal, not an OpenAI model id. Pass azure_deployment (or the older deployment_id) with the exact deployment name, plus azure_endpoint and a dated api_version like 2024-02-01. A 404 DeploymentNotFound almost always means the deployment name is wrong or lives in a different resource.

Index and query with the same model

Vectors from text-embedding-3-small and text-embedding-3-large are not compatible. If you index a store with one deployment and later query with another, similarity scores become meaningless. Pin the deployment in config and re-embed the whole corpus whenever you change models.

Batch size vs. token-per-minute quota

embed_documents batches requests, but Azure enforces a per-deployment TPM quota. For large corpora lower chunk_size so each batch stays under quota, or you will hit 429 rate limits mid-index. LangChain retries on 429 by default; raise the quota in the portal for sustained throughput.

Keyless auth for production

Instead of AZURE_OPENAI_API_KEY you can pass azure_ad_token_provider backed by DefaultAzureCredential. This avoids storing long-lived keys and works with managed identities on Azure-hosted apps, which is usually what enterprise compliance reviews require.

Import

python
from langchain_openai import AzureOpenAIEmbeddings

Configuration

Parameter Type Default Purpose
deployment_id str None Azure deployment ID

Usage Examples

Configure an Azure deployment and embed one query

python
from langchain_openai import AzureOpenAIEmbeddings

embeddings = AzureOpenAIEmbeddings(
    azure_deployment='text-embedding-3-small',
    azure_endpoint='https://my-resource.openai.azure.com/',
    api_version='2024-02-01',
)
vector = embeddings.embed_query('What is retrieval augmented generation?')
print(len(vector))

Index documents into a vector store with batching

python
from langchain_openai import AzureOpenAIEmbeddings
from langchain_chroma import Chroma

embeddings = AzureOpenAIEmbeddings(
    azure_deployment='text-embedding-3-large',
    api_version='2024-02-01',
    chunk_size=256,
)
store = Chroma.from_documents(docs, embeddings)
hits = store.similarity_search('billing policy', k=4)

Keyless auth with Azure AD token provider

python
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
from langchain_openai import AzureOpenAIEmbeddings

token_provider = get_bearer_token_provider(
    DefaultAzureCredential(),
    'https://cognitiveservices.azure.com/.default',
)
embeddings = AzureOpenAIEmbeddings(
    azure_deployment='text-embedding-3-small',
    azure_endpoint='https://my-resource.openai.azure.com/',
    api_version='2024-02-01',
    azure_ad_token_provider=token_provider,
)

Common Pitfalls

❌ Forget Azure credentials

✅ Set AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT

Alternative Embedding Models

Model When to Use
OpenAIEmbeddings For standard OpenAI access

Browse the full LangChain API reference index to explore more classes, methods, and decorators, or start with the LangChain introduction tutorial for end-to-end context on building with AzureOpenAIEmbeddings and the wider framework.

AzureOpenAIEmbeddings FAQ

What is AzureOpenAIEmbeddings in LangChain?

Use Azure-hosted OpenAI embeddings. AzureOpenAIEmbeddings is the LangChain wrapper for OpenAI embedding models served through Microsoft Azure OpenAI rather than OpenAI directly. The vectors it returns are identical in quality to OpenAIEmbeddings — it is the same text-embedding-3-small, text-embedding-3-large, and text-embedding-ada-002 models underneath — but requests are routed to your Azure resource, billed through your Azure subscription, and kept inside whatever region and network boundary your compliance t…

Which package provides AzureOpenAIEmbeddings?

DevShelfHub documents AzureOpenAIEmbeddings from the langchain-openai package. Pin your installed LangChain version and match imports to the snippet on this page.

When should I use AzureOpenAIEmbeddings?

You're on Azure or need Azure's enterprise features. Use AzureOpenAIEmbeddings for Azure deployments.

When should I avoid using AzureOpenAIEmbeddings?

For simple projects not on Azure.

How do I import AzureOpenAIEmbeddings in Python?

from langchain_openai import AzureOpenAIEmbeddings

Where can I explore more LangChain API reference pages?

Open the LangChain API reference index on DevShelfHub to browse classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.