Azure / Azure/azure-sdk-for-python
[Cosmos] [Embedding V0] Unit tests for embedding generation
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 3.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 193
Description
# Unit tests for embedding generation
Parent: 46729
Depends on: 46730, 46731, 46732, 46733, 46734
## Goal
Exercise the new code paths end-to-end with mocks (no emulator). Lives under `sdk/cosmos/azure-cosmos/tests/`.
## Scope
1. **`_PartitionedQueryExecutionInfo` parser**:
- Returns `embeddingParameterMap` from leaf `queryInfo`.
- Returns `embeddingParameterMap` from `hybridSearchQueryInfo`.
- Returns `{}` when neither is present.
2. **`_QueryFeature.EmbeddingGeneration`** advertised string:
- Sync `_GetQueryPlanThroughGateway`: token present iff `options["embeddingGenerator"] is not None`.
- Async `_GetQueryPlanThroughGateway`: same.
3. **`_resolve_embeddings`** (sync + async):
- Map empty → no-op, parameters list unchanged identity.
- Map non-empty + no generator → `ValueError` mentioning `embedding_generator`.
- Generator returns wrong cardinality → `ValueError` with both counts.
- Generator returns null at index N → `ValueError` mentioning index N.
- Generator returns valid vectors → params extended with `{"name": key, "value": [...]}` in **stable** order regardless of map insertion order.
- Original `self._parameters` list **identity** unchanged (test that the helper does not mutate the caller's list).
- Async aggregator with sync generator → `TypeError` early.
4. **Diagnostics** (mock the OTel tracer):
- Span named `cosmos.embedding_generation` is recorded.
- Attributes: count, generator_type, latency_ms.
- On generator exception → span records the error.
- When no tracer is configured → no-op (no exceptions, no extra calls).
5. **Pipeline / dispatch**:
- Mock plan triggers hybrid-search aggregator with mocked generator → component queries' `parameters` include the embedding entries.
- Mock plan triggers fast-fail when `embeddingGenerator` is absent.
## Files touched
- `sdk/cosmos/azure-cosmos/tests/test_query_execution_info.py` (new or extended)
- `sdk/cosmos/azure-cosmos/tests/test_embedding_generation.py` (new — sync)
- `sdk/cosmos/azure-cosmos/tests/test_embedding_generation_async.py` (new — async)
- `sdk/cosmos/azure-cosmos/tests/test_query_plan_features.py` (or wherever the supported-features header is asserted today)
## Acceptance
- All new tests pass on `pytest`.
- Coverage of `_resolve_embeddings` (sync + async) at 100 %.
- No emulator dependency in any of these tests.
Contributor guide
Assessment
This issue has not been assessed yet.