---
name: kimaai_embedding_vector_metadata
type: filter
since: 1.4.2
tier: premium
feature: embeddings
area: embedding-search
summary: Adds your own fields to the metadata stored with each chunk in the vector database, to filter the knowledge search by them.
parameters:
  - name: meta
    type: array
    description: The 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).
  - name: post
    type: WP_Post
    description: The post the chunk belongs to.
  - name: chunk
    type: array
    description: The chunk, with text, chunk_index, heading_path, anchor, token_count, start_char and end_char.
  - name: clean
    type: array
    description: The post's prepared text, with lang, text, title and html.
returns:
  type: array
  description: The metadata to store.
---

# 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.

## Example

```php
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
);
```

## Related

- `kimaai_kb_search_meta_filter`: filters the knowledge search by these fields.
- `kimaai_embedding_chunk_text`: changes the text a chunk is embedded with.
