kimaai_embedding_vector_metadata

When it fires

In a sync of the knowledge base, for each chunk that is embedded, after its vector came back from the AI provider and before it is sent to the vector database. Unchanged chunks are skipped by a sync and do not pass it, and the metadata is not part of what tells a chunk changed: after adding or changing a callback, run a forced sync (Force re-sync in the Sync tab, or wp kimaai vectors sync --force) so every chunk gets the new fields.

Add fields, do not remove or rename KimaAI’s: the knowledge search reads post_id, title, post_url, anchor, heading and chunk_text, and filters by lang, post_type, access and the tax_ fields. Use strings, numbers, booleans or lists of strings, which every vector database stores. A changed access does not widen who sees a chunk: every hit is checked against the post’s current rules before it is used.

Parameters

NameTypeDescription
metaarrayThe metadata KimaAI stores with the chunk (vector_id, post_id, post_type, mime_type, post_url, slug, title, lang, access, heading, chunk_index, model, dim, token_count, chunk_text, anchor and a tax_<taxonomy> list per scope taxonomy).
postWP_PostThe post the chunk belongs to.
chunkarrayThe chunk, with text, chunk_index, heading_path, anchor, token_count, start_char and end_char.
cleanarrayThe post’s prepared text, with lang, text, title and html.

Returns

array: The metadata to store.

Example

add_filter(
  'kimaai_embedding_vector_metadata',
  function (array $meta, WP_Post $post): array {
    // Who a document is written for, from a custom field: the knowledge search can filter by it.
    $audience = (string) get_post_meta($post->ID, 'audience', true);
    $meta['audience'] = $audience !== '' ? $audience : 'everyone';

    return $meta;
  },
  10,
  2
);
  • kimaai_kb_search_meta_filter: filters the knowledge search by these fields.
  • kimaai_embedding_chunk_text: changes the text a chunk is embedded with.

What are your feelings