When it fires
Each time the knowledge search runs: when the AI searches the knowledge base while answering in the chatbot or a search answer, and when the MCP tool that inspects retrieval runs the same search. The filter already holds what the settings ask for: the visitor’s language when answers are limited to it, the allowed post types and the scope’s terms.
The fields are the ones stored with each chunk, KimaAI’s and your own from kimaai_embedding_vector_metadata. A chunk without a field does not match a filter on it, so give every chunk the field (a forced sync) before you filter by it. Who may see what is added after your callback and cannot be changed by it, and every hit is checked against the post’s rules before it is used.
With hybrid search on, the keyword search gets the same filter but applies only post_type, lang and the tax_ fields: narrow it by your own fields with kimaai_keyword_search_query_args.
Parameters
| Name | Type | Description |
|---|---|---|
meta_filter | array | Field => value or list of values; every field must match, a list matches any of its values. Set from the settings with lang, post_type and a tax_<taxonomy> list per scope taxonomy. |
args | array | The arguments of the search tool call, with query and an optional post_type the AI asked for. |
payload | array | The request as the tool call gets it, with chatbot_settings and toolConfig. |
Returns
array: The filter.
Example
add_filter(
'kimaai_kb_search_meta_filter',
function (array $meta_filter): array {
// The chatbot answers from content for everyone and for consumers, never from the dealer documents.
$meta_filter['audience'] = ['everyone', 'consumers'];
return $meta_filter;
}
);
Related
kimaai_embedding_vector_metadata: stores your own fields with each chunk.kimaai_keyword_search_query_args: narrows the keyword search of hybrid search.