Cosmos DB trigger for Functions embedding generation

AI-200 By islever Editorial Last updated

Short answer

C Use an Azure Cosmos DB trigger so Azure Functions react to the container change feed, generate embeddings for new or updated documents, and send Service Bus messages that trigger search index updates.

Question

You need to configure Azure Functions to generate vector embeddings according to a planned environment application architecture in which Azure Functions generate embeddings of Azure Cosmos DB for NoSQL-hosted documents and send messages to Service Bus to trigger search index updates. Which trigger type should you use?
  1. Event Grid
  2. Service Bus
  3. Azure Cosmos DB Correct Answer
  4. HTTP

Key Takeaways

An Azure Cosmos DB trigger (Option C) is the correct way to make Azure Functions react to document changes in a Cosmos DB for NoSQL container. Because the trigger consumes the container's change feed, it can generate vector embeddings for new or updated documents and then send Service Bus messages that trigger search index updates without an HTTP caller.

Expert Analysis

An Azure Cosmos DB trigger runs an Azure Function in response to changes recorded in a Cosmos DB container's change feed. This event-driven connection lets the function process newly added or updated records, generate their vector embeddings, and place a message on Service Bus without requiring an HTTP caller or an unrelated messaging trigger.

The deciding constraint is the direction of event flow: document mutations in the Azure Cosmos DB for NoSQL container must initiate embedding generation, while Service Bus is the downstream notification channel for search index updates. A trigger must therefore sit on the Cosmos DB side of the pipeline, not on the Service Bus side and not behind an HTTP caller.

Option C, the Azure Cosmos DB trigger, satisfies that constraint directly. A function using this trigger is invoked by the container's change feed when documents are inserted or updated. The function receives the changed Cosmos DB document, generates its vector embedding, and can then send a Service Bus message—through an output binding or the Service Bus client—to signal that the search index needs updating. The trigger, not an external producer, supplies the initiating event, which is exactly what the stated architecture requires.

Option A, Event Grid, is aimed at Event Grid event delivery. Nothing in the architecture defines an Event Grid topic or a publisher that converts Cosmos DB document changes into Event Grid events. Substituting an Event Grid trigger would therefore add an event-forwarding component and still would not provide the Cosmos DB change-feed payload directly, so it does not meet the requirement as cleanly as the native Cosmos DB trigger.

Option B, Service Bus, reverses the pipeline. A Service Bus trigger fires when a message arrives on a queue or topic, so something else would have to detect Cosmos DB document changes and publish a message before the function could generate embeddings. In the planned flow, Service Bus messages are produced after embedding generation to trigger search index updates; making Service Bus the trigger would create a circular or inverted design and leave the original document change unhandled.

Option D, HTTP, is request-driven. It would require an external caller to invoke the function for each document that needs an embedding, adding a synchronous dependency and a component that watches the Cosmos DB container. The planned architecture removes exactly that need by using the change feed as the event source. An HTTP trigger also lacks any continuation or checkpoint state for the document stream.

The checkpointing mechanism behind the choice

The mechanism the architecture relies on but never states is change-feed checkpointing through a leases container. The Cosmos DB trigger does not rescan the entire NoSQL container on every invocation; it reads the change feed and records progress in leases. As the function processes changes—new or updated documents that need embeddings—the lease advances. If a batch fails, those changes can be delivered again, so the embedding and Service Bus emission logic must tolerate repeat processing. That is still the correct fit here, because the trigger maintains the document-stream position that HTTP and Service Bus triggers do not possess. The leases container is the operational detail to configure alongside the monitored container and the function's Cosmos DB connection.

Official Reference

Exam Strategy

Identify the event source that must start the function before comparing trigger types. When the requirement is to react to inserts or updates in a Cosmos DB for NoSQL container, select the Cosmos DB trigger and treat Service Bus as a downstream output, not the trigger. HTTP triggers fit caller-driven work, while Event Grid needs a defined event publisher. This source-versus-output check quickly eliminates inverted pipeline choices.

Practice All AI-200 Questions

Access 69 questions with complete answers and detailed explanations.

View Full AI-200 Practice Test →

← Back to AI-200 Study Guide