Skip to main content
GraphRAG seamlessly integrates with Azure OpenAI to provide enterprise-grade LLM capabilities. This guide walks you through setting up Azure OpenAI for use with GraphRAG.

Prerequisites

Before starting, ensure you have:
  • An active Azure subscription
  • Access to Azure OpenAI Service
  • Deployed models for chat completion and embeddings
  • GraphRAG installed (pip install graphrag)

Azure OpenAI setup

1

Deploy Azure OpenAI models

In the Azure Portal, deploy the required models:
  1. Navigate to your Azure OpenAI resource
  2. Go to “Model deployments”
  3. Deploy a chat model (e.g., gpt-4o, gpt-4-turbo)
  4. Deploy an embedding model (e.g., text-embedding-3-small)
Note your deployment names - you’ll need these for configuration.
2

Gather connection information

Collect the following from your Azure OpenAI resource:
  • Endpoint URL: https://YOUR-RESOURCE-NAME.openai.azure.com/
  • API Key: Found under “Keys and Endpoint”
  • API Version: Use 2024-02-15-preview or later
  • Deployment names: The names you gave your models
3

Initialize GraphRAG project

Configuration

Environment variables

The recommended approach is to store sensitive information in environment variables.
1

Edit .env file

Open the .env file created by graphrag init:
.env
Never commit your .env file to version control. Keep your API keys secure.
2

Configure settings.yaml

Edit settings.yaml to use Azure OpenAI:
settings.yaml

Rate limiting

Azure OpenAI has token-per-minute (TPM) and requests-per-minute (RPM) limits. Configure these in your settings:
settings.yaml
Check your Azure OpenAI quota in the Azure Portal under your resource’s “Quotas” section.

Model configurations

Chat models

Different Azure OpenAI chat models have different capabilities and costs:
Latest and most capable model:
Best for: Complex reasoning, high-quality extractions

Embedding models

Balanced performance and cost:
Dimensions: 1536

Multiple model configurations

You can use different models for different workflows:
settings.yaml

Azure AI Search integration

For production deployments, use Azure AI Search as your vector store:
settings.yaml
1

Create Azure AI Search resource

In the Azure Portal, create a new Azure AI Search service.
2

Get connection details

  • URL: https://YOUR-SERVICE-NAME.search.windows.net
  • API Key: Found in “Keys” section
3

Add to .env

.env

Testing your configuration

Verify your Azure setup before running a full index:
1

Run dry run

This validates your configuration without making API calls.
2

Test with small dataset

Create a small test file:
Run indexing:
3

Monitor Azure metrics

Check the Azure Portal to verify:
  • API calls are succeeding
  • Token usage is within limits
  • No throttling errors

Cost optimization

Optimize costs when using Azure OpenAI:

1. Use appropriate models

Development

Use GPT-3.5 Turbo for testing and development

Production

Use GPT-4o or GPT-4 Turbo for final production runs

2. Enable caching

settings.yaml
Caching stores LLM responses to avoid redundant API calls.

3. Optimize chunking

settings.yaml

4. Batch processing

settings.yaml
Reducing max_gleanings will decrease extraction quality. Test with your data to find the right balance.

Authentication methods

API key authentication

The standard method shown above:
.env

Azure AD / Entra ID authentication

For enhanced security, use Azure AD:
settings.yaml
Azure AD authentication requires the azure-identity Python package: pip install azure-identity

Troubleshooting

Common issues

Cause: Invalid API key or authentication failureSolution:
  • Verify your API key in the Azure Portal
  • Ensure the key is correctly set in .env
  • Check that api_base matches your resource endpoint
Cause: Incorrect deployment name or endpointSolution:
  • Verify deployment_name matches your Azure deployment exactly
  • Check that api_base ends with / or doesn’t, based on API version
  • Ensure the model is deployed in the same region as your endpoint
Cause: Exceeding Azure OpenAI quotaSolution:
  • Reduce requests_per_minute and tokens_per_minute in config
  • Request quota increase in Azure Portal
  • Implement retry logic with exponential backoff
Cause: Model not deployed or incorrect API versionSolution:
  • Deploy the model in Azure Portal
  • Use API version 2024-02-15-preview or later
  • Match model parameter to your deployment name

Validation checklist

  • Azure OpenAI resource is created and active
  • Chat model (e.g., gpt-4o) is deployed
  • Embedding model (e.g., text-embedding-3-small) is deployed
  • API key is copied to .env file
  • api_base URL is correct
  • deployment_name matches Azure deployment exactly
  • model_provider is set to azure
  • Rate limits match your Azure quota
  • Dry run completes without errors

Example complete configuration

Here’s a complete working configuration for Azure:

Next steps

Configuration reference

Explore all configuration options

CLI usage

Learn GraphRAG commands

Best practices

Optimize your implementation

Migration guide

Upgrade between versions