Keeping Embeddings Current
This lesson compares the methods for regenerating embeddings when source data changes.
Learning outcomes
After completing this lesson, you will be able to:
- Explain why the model should not be called in the write path.
- Compare triggers, Change Tracking, CDC, Azure Functions, Logic Apps and Foundry-based pipelines.
- Describe a queue-based maintenance pattern.
The maintenance problem
When a description is edited, its old embedding still represents the old text, so search returns outdated matches until it is regenerated. A maintenance method must detect inserts, updates of the embedded columns and deletes, call the model reliably, and do so without slowing the application's writes. Calling the model synchronously in the write path couples the application's availability to the model's.
Methods
The methods differ in latency, reliability and where the logic runs, as the following table summarizes.
| Method | How it works | Considerations |
|---|---|---|
| Table trigger | Marks rows stale or queues keys in the same transaction | Never call the model in the trigger; keep it tiny |
| Change Tracking | A scheduled job reads changed keys since its last version | Low overhead; latency equals the schedule |
| CDC | A job reads before and after values | Can skip changes that do not touch embedded columns; more overhead |
| Azure Functions SQL trigger | Serverless function receives changed rows (uses Change Tracking) | Near real time; code outside the database |
| Azure Logic Apps | Polling workflow calls the model and writes back | Low-code; minutes of latency |
| Microsoft Foundry | Application or agent pipelines built on Foundry generate embeddings with the deployed model | Logic lives in the application; Foundry hosts the models all methods use |
Embedding maintenance methods
A queue-based pattern
A robust in-database pattern uses a small trigger that records keys in a queue table, and a background job, such as an elastic job, an Azure Function on a timer or a SQL Agent job on SQL Server, that processes the queue in batches and calls AI_GENERATE_EMBEDDINGS. Writes stay fast, model outages only delay embeddings, and a hash comparison skips rows whose embedded text did not change.
CREATE TABLE Support.EmbeddingQueue (ArticleID int PRIMARY KEY, QueuedUtc datetime2 NOT NULL DEFAULT SYSUTCDATETIME());
GO
CREATE OR ALTER TRIGGER Support.trg_Article_QueueEmbedding ON Support.Article
AFTER INSERT, UPDATE
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO Support.EmbeddingQueue (ArticleID)
SELECT i.ArticleID FROM inserted AS i
WHERE NOT EXISTS (SELECT 1 FROM Support.EmbeddingQueue AS q WHERE q.ArticleID = i.ArticleID);
END;The following diagram follows a change through the queue to a new embedding.

The queue pattern
Choosing a method
Support articles are edited a few hundred times a day. Embeddings must be updated within five minutes, the team prefers to keep all logic in the database, and article saves must not fail when the model endpoint is unavailable. Which method fits best?
Use a lightweight trigger (or Change Tracking) to record changed article keys, and a scheduled job every few minutes that re-embeds queued articles in batches with AI_GENERATE_EMBEDDINGS. The logic stays in the database, saves never wait for the model, and the schedule meets the five-minute target. A trigger that calls the model directly would fail saves during outages, and an Azure Function moves logic outside the database, which the team wants to avoid.
Why should not a trigger call AI_GENERATE_EMBEDDINGS directly?
Show answer
It would slow every write and fail inserts and updates whenever the model endpoint is slow or unavailable.
Exam Tips
Remember for the exam
- Never call the model synchronously in the write path; queue the work.
- Schedule-based with low overhead: Change Tracking or a trigger-fed queue table.
- Serverless near real time: Azure Functions SQL trigger.
- Skip unchanged text with a hash comparison.