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), never in the request that saved it: it is an outside call that can wait.
// domains/support/subscribers/embed_article.jadposubscriber 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),
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.
Markdown for agents: /docs/keeping-embeddings-current.md.Built from Jadpo main at a707efb.