kimaai_embedding_index_changed

When it fires

Whenever the vector database confirmed a change to the knowledge base, in the request, background job or WP-CLI command that made it:

  • Chunks stored: in a sync, after the vector database confirmed a batch of chunks, once for every chunk of the batch: a sync that embeds 200 chunks fires it 200 times. Chunks a sync skips because they did not change do not fire it.
  • Chunks removed: once for every delete the vector database confirmed, not once per chunk: the stale chunks of a post that got shorter (pruned in a sync), a post’s chunks when it is unpublished, deleted or taken out of the knowledge base, the chunks of deleted posts removed by the reconcile (weekly when switched on, or wp kimaai vectors reconcile), chunks deleted in the admin or with WP-CLI. KimaAI removes its own rows of the chunks right after.
  • A collection deleted in the admin or with WP-CLI: once.

A delete the vector database refused fires nothing. The action passes no arguments: it says that the knowledge base changed, not what changed.

KimaAI hooks it itself: the search answer cache counts up its version, once per request, so no cached answer is served from the old content. Do the same in your callback, as the example does, rather than repeat the work for every change.

Example

add_action(
  'kimaai_embedding_index_changed',
  function (): void {
    // A sync stores or removes many chunks: clearing the cache once per request is enough.
    static $cleared = false;
    if ($cleared) {
      return;
    }
    $cleared = true;

    delete_transient('my_theme_popular_questions');
  }
);
  • kimaai_embedding_vector_metadata: changes what is stored with each chunk.

What are your feelings