Azure / Azure/azure-sdk-for-python

[Cosmos] [Embedding V0] Unit tests for embedding generation

Aperta
#46,735 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Cosmos feature-request
Lingua principale
Python
Stelle
5.6k
Fork
3.4k
Merge medio
2g
PR unite (30g)
217

Descrizione

# 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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con i test esistenti di query plan ed execution in sdk/cosmos/azure-cosmos/tests/, in particolare test_query_execution_info.py e test_query_plan_features.py. Leggi l’implementazione relativa a embedding ed esegui i file pytest mirati, quindi aggiungi i test sync e async indicati nell’issue. Il lavoro è completato quando parser, intestazioni delle feature, risoluzione di embedding, diagnostica e percorsi della pipeline simulati soddisfano i casi di accettazione elencati senza un emulatore.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
azure, python
Ambito
databases, testing
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
52/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.