Azure / Azure/azure-sdk-for-python
[Cosmos] [Embedding V0] Unit tests for embedding generation
- Vorherrschende Sprache
- Python
- Sterne
- 5.6k
- Forks
- 3.4k
- Ø Merge
- 2 T. 2 Std.
- Gemergte PRs (30 T.)
- 213
Beschreibung
# 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.
Beitragsleitfaden
Rechercherichtung
Beginne mit den vorhandenen Query-Plan- und Execution-Tests unter sdk/cosmos/azure-cosmos/tests/, insbesondere test_query_execution_info.py und test_query_plan_features.py. Lies die embedding-bezogene Implementierung und führe die fokussierten pytest-Dateien aus; füge anschließend die in der Issue genannten Sync- und Async-Tests hinzu. Als erledigt gilt die Aufgabe, wenn Parser, Feature-Header, embedding-Auflösung, Diagnostik und die gemockten Pipeline-Pfade die aufgeführten Akzeptanzfälle ohne Emulator erfüllen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- azure, python
- Bereich
- databases, testing
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 52/100