Skip to content

[WIP][EGS]: Add azure-cosmos-ai companion package with Azure OpenAI embedding provider#47003

Open
aayush3011 wants to merge 10 commits into
Azure:mainfrom
aayush3011:users/akataria/EGS_AI_package
Open

[WIP][EGS]: Add azure-cosmos-ai companion package with Azure OpenAI embedding provider#47003
aayush3011 wants to merge 10 commits into
Azure:mainfrom
aayush3011:users/akataria/EGS_AI_package

Conversation

@aayush3011
Copy link
Copy Markdown
Member

@aayush3011 aayush3011 commented May 19, 2026

Description

Introduces a new sibling package, azure-cosmos-ai (1.0.0b1), that ships the default Azure OpenAI implementation of the EmbeddingProvider Protocol introduced in azure-cosmos 4.16.0b3. The provider is used by the Cosmos SDK to generate vector embeddings at query time for GenerateEmbeddings(...) expressions on containers whose vectorEmbeddingPolicy.embeddingSource points at an Azure OpenAI deployment.

What's in the package

  • azure.cosmos.ai.AzureOpenAIEmbeddingProvider (sync) and azure.cosmos.ai.aio.AzureOpenAIEmbeddingProvider (async).
  • Three credential shapes per surface:
    • str (raw Azure OpenAI API key)
    • azure.core.credentials.AzureKeyCredential
    • TokenCredential (sync) / AsyncTokenCredential (async) for Entra/RBAC, wired through get_bearer_token_provider against https://cognitiveservices.azure.com/.default.
  • Per‑endpoint client caching, context‑manager support, and idempotent close() that releases the cached AzureOpenAI / AsyncAzureOpenAI client(s).
  • Empty texts short‑circuits without a network call and returns an EmbeddingResult with vectors=[], total_tokens=0, latency=0.0.

Tests

Each test module exposes two pytest classes:

  • TestAzureOpenAIProvider / TestAzureOpenAIProviderAsync: 12 fully mocked unit tests; always collected.
  • TestAzureOpenAIProviderLive / TestAzureOpenAIProviderLiveAsync: 5 opt‑in live tests against a real Azure OpenAI resource. Gated by COSMOS_AI_LIVE_TESTS=1 plus AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_EMBEDDING_DEPLOYMENT, AZURE_OPENAI_EMBEDDING_DIMENSIONS, and (for API‑key paths) AZURE_OPENAI_API_KEY. Covers raw key, AzureKeyCredential, DefaultAzureCredential, the empty‑texts short‑circuit, and per‑endpoint client caching.

Related

Companion to the EGSInterface and EGSPolicy work on azure-cosmos (EmbeddingProvider Protocol, EmbeddingResult dataclass, and the new embeddingSource fields on VectorEmbeddingPolicy).

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Copilot AI review requested due to automatic review settings May 19, 2026 21:27
@aayush3011 aayush3011 requested review from a team, danieljurek, lmazuel, msyyc and scbedd as code owners May 19, 2026 21:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new sibling package, azure-cosmos-ai (1.0.0b1), which provides a default Azure OpenAI-backed implementation of the EmbeddingProvider contract used by azure-cosmos to generate vector embeddings for GenerateEmbeddings(...) query expressions.

Changes:

  • Adds new azure-cosmos-ai package with sync/async AzureOpenAIEmbeddingProvider, credential support, endpoint-based client caching, and close/context-manager behavior.
  • Adds unit tests (mocked) plus opt-in live tests, and provides samples + README + changelog for the new package.
  • Updates Cosmos service CI artifact list to include azure-cosmos-ai.

Reviewed changes

Copilot reviewed 21 out of 22 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
sdk/cosmos/ci.yml Adds azure-cosmos-ai to the Cosmos CI artifact list.
sdk/cosmos/azure-cosmos-ai/tests/test_azure_openai_provider.py Sync unit + opt-in live tests for the provider.
sdk/cosmos/azure-cosmos-ai/tests/test_azure_openai_provider_async.py Async unit + opt-in live tests for the provider.
sdk/cosmos/azure-cosmos-ai/tests/conftest.py Test-time stub injection for EmbeddingResult (for local/CI compatibility).
sdk/cosmos/azure-cosmos-ai/setup.py Package setup/configuration and dependencies.
sdk/cosmos/azure-cosmos-ai/sdk_packaging.toml Packaging automation configuration.
sdk/cosmos/azure-cosmos-ai/samples/sample_embedding_provider.py Sync usage sample showing API key and Entra scenarios.
sdk/cosmos/azure-cosmos-ai/samples/sample_embedding_provider_async.py Async usage sample showing API key and Entra scenarios.
sdk/cosmos/azure-cosmos-ai/README.md Package overview, examples, credential matrix, troubleshooting notes.
sdk/cosmos/azure-cosmos-ai/pyproject.toml Enables repo build checks (mypy/pylint) for this package.
sdk/cosmos/azure-cosmos-ai/MANIFEST.in Source distribution include rules (samples/tests/namespace files/py.typed).
sdk/cosmos/azure-cosmos-ai/LICENSE MIT license file for the package.
sdk/cosmos/azure-cosmos-ai/dev_requirements.txt Dev dependencies for local builds/tests.
sdk/cosmos/azure-cosmos-ai/CHANGELOG.md Initial release entry for 1.0.0b1 (Unreleased).
sdk/cosmos/azure-cosmos-ai/azure/cosmos/ai/py.typed Marks the package as typed.
sdk/cosmos/azure-cosmos-ai/azure/cosmos/ai/aio/_azure_openai_provider.py Async Azure OpenAI provider implementation.
sdk/cosmos/azure-cosmos-ai/azure/cosmos/ai/aio/init.py Exposes async provider class.
sdk/cosmos/azure-cosmos-ai/azure/cosmos/ai/_version.py Package version constant.
sdk/cosmos/azure-cosmos-ai/azure/cosmos/ai/_azure_openai_provider.py Sync Azure OpenAI provider implementation.
sdk/cosmos/azure-cosmos-ai/azure/cosmos/ai/init.py Exposes provider + __version__.
sdk/cosmos/azure-cosmos-ai/azure/cosmos/init.py Introduces an azure.cosmos package initializer (namespace-style).
sdk/cosmos/azure-cosmos-ai/azure/init.py Introduces an azure package initializer (namespace-style).

Comment thread sdk/cosmos/azure-cosmos-ai/samples/sample_embedding_provider_async.py Outdated
Comment thread sdk/cosmos/azure-cosmos-ai/samples/sample_embedding_provider.py Outdated
Comment thread sdk/cosmos/azure-cosmos-ai/azure/cosmos/__init__.py
Comment thread sdk/cosmos/azure-cosmos-ai/setup.py
Comment thread sdk/cosmos/azure-cosmos-ai/MANIFEST.in Outdated
Comment thread sdk/cosmos/ci.yml
@aayush3011 aayush3011 changed the title [EGS]: Add azure-cosmos-ai companion package with Azure OpenAI embedding provider [WIP][EGS]: Add azure-cosmos-ai companion package with Azure OpenAI embedding provider May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants