# Keeping embeddings current

When a record's text changes, its embedding must be made again. Do that
in a subscriber, which runs after the change is saved
([Subscribers](subscribers.md)), never in the
request that saved it: it is an outside call that can wait.

```jadpo
// domains/support/subscribers/embed_article.jadpo
subscriber embed_article {
    on: HelpArticleSaved
    run: refresh_meaning(event.article_id)
}

// domains/support/actions/refresh_meaning.jadpo
/// Remakes a help article's embedding from its current text.
action refresh_meaning(
    article_id: HelpArticle.id
) fails EmbeddingDelayed, HelpArticleNotFound -> HelpArticle {
    var article: HelpArticle = attempt HelpArticle.get(article_id)
    var fresh_meaning: ArticleMeaning = attempt ai.embed(article.body, as: ArticleMeaning) {
        timed_out: EmbeddingDelayed
        over_budget: EmbeddingDelayed
        too_long: EmbeddingDelayed
    }
    return HelpArticle.update(article) {
        set: {
            body_meaning: fresh_meaning
        }
    }
}
```

After you change the embedding model, every record needs a new
embedding. Make them in a batch with `batches.each`
([Batches: work over many items](batches-work-over-many-items.md)),
which can resume and stays within the daily limit. An item over budget
is recorded as the batch's problem and retried on its next run.
