semantic Classifier
semantic Classifier
Defines a classifier that detects labeled content by meaning, comparing embedding vectors by cosine similarity instead of matching exact text.
The semantic classifier maps each configured label to a list of example phrases. Each phrase is embedded once into a vector, and a value is detected for a label when its own vector has a cosine similarity at or above the threshold to any of that label's phrases, even when the value shares no wording with them. Use it for content that is defined by what it says rather than by its shape, such as a prompt injection attempt.
embeddings:
embedding0:
type: openai
options:
model: text-embedding-3-small
credentials:
api-key: ${{env.OPENAI_API_KEY}}
stores:
store0:
type: memory
classifiers:
moderator0:
type: semantic
embedding: embedding0
store: store0
options:
threshold: 0.85
labels:
prompt.injection:
- "ignore previous instructions"
- "disregard your system prompt"A classifier is applied to a message value by the classify model. If the example phrases aren't embedded in time, or the value can't be embedded, the value is treated as detected, so the message is rejected rather than passed through unchecked.
Configuration (* required)
type: semantic
const
Specifies the classifier is semantic.
embedding*
string
Name of a configured embedding used to turn each example phrase, and each value being classified, into a vector. Any registered embedding provider works here, such as openai, aws-bedrock ★Zilla Plus, or ibm-watsonx-ai ★Zilla Plus.
store*
string
Name of a configured store (see memory, redis ★Zilla Plus, and hazelcast ★Zilla Plus) used to embed each example phrase only once and share the result, rather than have every engine worker, and with a distributed store every replica, embed the same phrases independently.
options*
object
The semantic specific options.
options:
threshold: 0.85
labels:
prompt.injection:
- "ignore previous instructions"options.threshold*
number| Minimum:0| Maximum:1
Minimum cosine similarity, between 0 and 1, at or above which a value is detected as one of a label's example phrases. The right value depends on the embedding, so measure the similarity of values that should and should not match, and place the threshold between them.
options.labels*
objectas map ofarrayofstring
Named labels to detect, each mapped to a non-empty list of example phrases. At least one label is required, and phrases must not be empty.
Label names are chosen freely, and are the names a consumer such as the classify model's reject refers to.

