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
-
_PartitionedQueryExecutionInfo parser:
- Returns
embeddingParameterMap from leaf queryInfo.
- Returns
embeddingParameterMap from hybridSearchQueryInfo.
- Returns
{} when neither is present.
-
_QueryFeature.EmbeddingGeneration advertised string:
- Sync
_GetQueryPlanThroughGateway: token present iff options["embeddingGenerator"] is not None.
- Async
_GetQueryPlanThroughGateway: same.
-
_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.
-
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).
-
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.
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
_PartitionedQueryExecutionInfoparser:embeddingParameterMapfrom leafqueryInfo.embeddingParameterMapfromhybridSearchQueryInfo.{}when neither is present._QueryFeature.EmbeddingGenerationadvertised string:_GetQueryPlanThroughGateway: token present iffoptions["embeddingGenerator"] is not None._GetQueryPlanThroughGateway: same._resolve_embeddings(sync + async):ValueErrormentioningembedding_generator.ValueErrorwith both counts.ValueErrormentioning index N.{"name": key, "value": [...]}in stable order regardless of map insertion order.self._parameterslist identity unchanged (test that the helper does not mutate the caller's list).TypeErrorearly.Diagnostics (mock the OTel tracer):
cosmos.embedding_generationis recorded.Pipeline / dispatch:
parametersinclude the embedding entries.embeddingGeneratoris 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
pytest._resolve_embeddings(sync + async) at 100 %.