[Cosmos] [Embedding V0] VectorEmbeddingPolicy: document and add typed support for embeddingSource
Parent: #46729
Background
The vectorEmbeddingPolicy on a container now supports an optional embeddingSource block inside each entry of vectorEmbeddings. This block carries the endpoint, deployment name, auth type, and source paths that the new azure-cosmos-embedding package reads to construct an AzureOpenAIEmbeddingGenerator.
Example container policy JSON:
{
"vectorEmbeddingPolicy": {
"vectorEmbeddings": [
{
"path": "/embedding",
"dataType": "float32",
"dimensions": 1536,
"distanceFunction": "cosine",
"embeddingSource": {
"sourcePaths": ["/title", "/abstract"],
"deploymentName": "text-embedding-3-small",
"modelName": "text-embedding-3-small",
"endpoint": "https://embedding-south-central.cognitiveservices.azure.com/",
"authType": "ApiKey"
}
}
]
}
}
Scope
Python's vector_embedding_policy is currently typed as dict[str, Any] and passed through transparently. This issue adds typed support for the new embeddingSource sub-object without breaking the existing raw-dict path.
1. Add TypedDict models
In azure/cosmos/_models.py (or documents.py — confirm preferred location with SDK conventions):
from typing import List, Literal, Optional
from typing_extensions import TypedDict
class EmbeddingSource(TypedDict, total=False):
sourcePaths: List[str]
deploymentName: str
modelName: str
endpoint: str
authType: Literal["ApiKey", "Entra"]
class VectorEmbedding(TypedDict, total=False):
path: str
dataType: Literal["float32", "float16", "uint8", "int8"]
dimensions: int
distanceFunction: Literal["cosine", "dotproduct", "euclidean"]
embeddingSource: EmbeddingSource # NEW
class VectorEmbeddingPolicy(TypedDict, total=False):
vectorEmbeddings: List[VectorEmbedding]
2. Update database.py (sync + async)
Update all vector_embedding_policy keyword parameter type annotations from dict[str, Any] to VectorEmbeddingPolicy — no behavioral change, just stronger typing.
3. Update ContainerProperties docstring (if applicable)
Update the docstring for vector_embedding_policy in ContainerProperties / database.py to document the new embeddingSource schema.
Acceptance criteria
TypedDict models are exported from azure.cosmos (or a supported sub-module).
mypy passes on a usage like:
source: EmbeddingSource = {"endpoint": "...", "deploymentName": "...", "authType": "ApiKey"}
- Existing containers without
embeddingSource continue to work unchanged (round-trip through dict[str, Any] still valid).
- Unit test: create a
VectorEmbedding TypedDict with and without embeddingSource, verify json.dumps round-trips correctly.
Files likely touched
sdk/cosmos/azure-cosmos/azure/cosmos/_models.py (or documents.py) — new TypedDict classes
sdk/cosmos/azure-cosmos/azure/cosmos/__init__.py — export new types
sdk/cosmos/azure-cosmos/azure/cosmos/database.py — updated type annotations (sync)
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_database.py — updated type annotations (async)
Dependencies
None — pure model/typing change, no behavioral change.
[Cosmos] [Embedding V0] VectorEmbeddingPolicy: document and add typed support for
embeddingSourceParent: #46729
Background
The
vectorEmbeddingPolicyon a container now supports an optionalembeddingSourceblock inside each entry ofvectorEmbeddings. This block carries the endpoint, deployment name, auth type, and source paths that the newazure-cosmos-embeddingpackage reads to construct anAzureOpenAIEmbeddingGenerator.Example container policy JSON:
{ "vectorEmbeddingPolicy": { "vectorEmbeddings": [ { "path": "/embedding", "dataType": "float32", "dimensions": 1536, "distanceFunction": "cosine", "embeddingSource": { "sourcePaths": ["/title", "/abstract"], "deploymentName": "text-embedding-3-small", "modelName": "text-embedding-3-small", "endpoint": "https://embedding-south-central.cognitiveservices.azure.com/", "authType": "ApiKey" } } ] } }Scope
Python's
vector_embedding_policyis currently typed asdict[str, Any]and passed through transparently. This issue adds typed support for the newembeddingSourcesub-object without breaking the existing raw-dict path.1. Add
TypedDictmodelsIn
azure/cosmos/_models.py(ordocuments.py— confirm preferred location with SDK conventions):2. Update
database.py(sync + async)Update all
vector_embedding_policykeyword parameter type annotations fromdict[str, Any]toVectorEmbeddingPolicy— no behavioral change, just stronger typing.3. Update
ContainerPropertiesdocstring (if applicable)Update the docstring for
vector_embedding_policyinContainerProperties/database.pyto document the newembeddingSourceschema.Acceptance criteria
TypedDictmodels are exported fromazure.cosmos(or a supported sub-module).mypypasses on a usage like:embeddingSourcecontinue to work unchanged (round-trip throughdict[str, Any]still valid).VectorEmbeddingTypedDict with and withoutembeddingSource, verifyjson.dumpsround-trips correctly.Files likely touched
sdk/cosmos/azure-cosmos/azure/cosmos/_models.py(ordocuments.py) — new TypedDict classessdk/cosmos/azure-cosmos/azure/cosmos/__init__.py— export new typessdk/cosmos/azure-cosmos/azure/cosmos/database.py— updated type annotations (sync)sdk/cosmos/azure-cosmos/azure/cosmos/aio/_database.py— updated type annotations (async)Dependencies
None — pure model/typing change, no behavioral change.