Domain 2: Develop AI Solutions by Using Azure Data Management Services (Part 1 of 3)
This lesson covers 4 exam topics: Cosmos DB for NoSQL: SDK and Queries, Cosmos DB Indexing, Consistency and Request Units, Vector Search in Cosmos DB, Cosmos DB Change Feed Processor. Each topic has a short video, then the notes: key facts, exam traps and what to check in the official docs.
1. Cosmos DB for NoSQL: SDK and Queries
Central question: How do apps connect to Cosmos DB for NoSQL and query items?
Facts
- Python:
CosmosClient(endpoint, credential=DefaultAzureCredential())→ database → container; items are schemaless JSON. - Point read (id + partition key) of a ~1 KB item costs 1 RU; queries cost more. Prefer point reads when you know id and partition key.
- Queries use SQL-like syntax with parameters (
SELECT * FROM c WHERE c.category = @cat); include the partition key to avoid cross-partition fan-out. - Every response reports its request charge (RU) (general background on header name
x-ms-request-charge).
Design guidance
Choose a high-cardinality partition key used in most queries; reuse one CosmosClient per app (singleton); use Entra ID instead of keys.
Exam traps
- Query when a point read works.
- Cross-partition queries for hot paths.
- New CosmosClient per request.
2. Cosmos DB Indexing, Consistency and Request Units
Central question: How do you cut RU cost and latency?
Indexing
- Default policy indexes every property with range indexes; modes Consistent and None (pure key-value or bulk loads); lazy is not for queried containers.
- Use includedPaths/excludedPaths to stop indexing unused (large) properties → cheaper writes; composite indexes for multi-property ORDER BY/filters; vector indexes for vector search.
Consistency
Five levels, strongest to weakest: Strong, Bounded staleness, Session, Consistent prefix, Eventual. Account default applies to all containers; clients can override (weaker) per request. Session is the common default (portal and CLI examples).
Throughput modes
Provisioned (RU/s in steps of 100), Autoscale (scales RU/s automatically for variable traffic), Serverless (pay per RU consumed).
Exam traps
- Strong consistency everywhere: higher latency and read cost.
- Indexing large unused properties (e.g. raw text blobs).
- Provisioned for spiky dev workloads instead of serverless/autoscale.
3. Vector Search in Cosmos DB
Central question: How do you store embeddings and run similarity search in Cosmos DB?
Facts
- Enable the vector search capability (
EnableNoSQLVectorSearch); define a container vector policy: path, data type, dimensions (default 1536), distance function (cosine default, dotproduct, euclidean). - Vector index types: flat (exact, 100% recall, max 505 dimensions), quantizedFlat (brute force over compressed vectors), diskANN (approximate, high recall, low latency and RU at scale; up to 4096 dimensions).
- Query with VectorDistance() in ORDER BY with TOP N; combine with WHERE filters and partition keys.
- Exclude the vector path from the regular index (general guidance from docs examples) to keep writes cheap.
- Store embeddings next to source data: no separate vector database to sync.
Exam traps
- flat index for 1536-dim vectors. Limit is 505; use quantizedFlat or diskANN.
- Different embedding model for queries and documents.
- Separate vector DB when data already lives in Cosmos DB.
4. Cosmos DB Change Feed Processor
Central question: How do you react to new or updated items?
Facts
Four components: 1. Monitored container: inserts and updates appear in its change feed. 2. Lease container: stores state and coordinates work across instances (same or different account). 3. Compute instance(s): host the processor, each with a unique instance name; partition ranges are distributed across instances. 4. Delegate: your code that handles each batch of changes.
- Modes: latest version (default; deletes not included) and all versions and deletes (preview).
- Scale out by adding instances with the same processor name and lease container.
Uses in AI apps (design guidance)
Generate embeddings for new documents, refresh caches, update search indexes, trigger downstream events; Azure Functions Cosmos DB trigger uses the change feed under the hood (general background).
Exam traps
- Polling with queries instead of the change feed.
- Forgetting the lease container.
- Expecting deletes in latest version mode. Use soft-delete flags or all versions and deletes.
References
- AI-200 study guide — checked Oct 22, 2026
- Quickstart: Python — checked Oct 22, 2026
- Request units — checked Oct 22, 2026
- Indexing policies — checked Oct 22, 2026
- Consistency levels — checked Oct 22, 2026
- Vector search in Cosmos DB for NoSQL — checked Oct 22, 2026
- Change feed processor — checked Oct 22, 2026
Check your understanding
Cheapest way to fetch one item?Show answerHide answer
Answer
Point read by id and partition key (1 RU for 1 KB).Read-your-own-writes per user, cheaply?Show answerHide answer
Answer
Session consistency.Function for similarity in queries?Show answerHide answer
Answer
VectorDistance.Where is processor progress stored?Show answerHide answer
Answer
Lease container.Avoid injection in queries?Show answerHide answer
Answer
Parameterized queries.