Package com.google.genkit.ai.evaluation
Class Evaluator<O>
java.lang.Object
com.google.genkit.ai.evaluation.Evaluator<O>
- Type Parameters:
O- the type of evaluator-specific options
- All Implemented Interfaces:
Action<EvalRequest,,List<EvalResponse>, Void> Registerable
Evaluator represents an evaluation action that assesses the quality of AI
outputs.
Evaluators are a core primitive in Genkit that allow you to measure and track the quality of your AI applications. They can be used to:
- Score outputs based on various criteria (accuracy, relevance, etc.)
- Compare outputs against reference data
- Run automated quality checks in CI/CD pipelines
- Monitor production quality over time
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating Evaluator instances. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <O> Evaluator.Builder<O> builder()Creates a new Evaluator builder.static <O> Evaluator<O> define(Registry registry, String name, String displayName, String definition, boolean isBilled, Class<O> optionsClass, EvaluatorFn<O> evaluatorFn) Defines a new evaluator with full options and registers it with the registry.static <O> Evaluator<O> define(Registry registry, String name, String displayName, String definition, EvaluatorFn<O> evaluatorFn) Defines a new evaluator and registers it with the registry.getDesc()Returns the descriptor of the action containing metadata, schemas, etc.getInfo()Gets the evaluator info.Returns the JSON schema for the action's input type.Returns additional metadata for the action.getName()Returns the name of the action.Returns the JSON schema for the action's output type.getType()Returns the type of the action.voidRegisters this primitive with the given registry.run(ActionContext ctx, EvalRequest input) Runs the action with the given input.run(ActionContext ctx, EvalRequest input, Consumer<Void> streamCallback) Runs the action with the given input and streaming callback.com.fasterxml.jackson.databind.JsonNoderunJson(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) Runs the action with JSON input and returns JSON output.ActionRunResult<com.fasterxml.jackson.databind.JsonNode> runJsonWithTelemetry(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) Runs the action with JSON input and returns the result with telemetry information.
-
Field Details
-
METADATA_KEY_DISPLAY_NAME
- See Also:
-
METADATA_KEY_DEFINITION
- See Also:
-
METADATA_KEY_IS_BILLED
- See Also:
-
-
Method Details
-
builder
Creates a new Evaluator builder.- Type Parameters:
O- the options type- Returns:
- a new builder
-
define
public static <O> Evaluator<O> define(Registry registry, String name, String displayName, String definition, EvaluatorFn<O> evaluatorFn) Defines a new evaluator and registers it with the registry.- Type Parameters:
O- the options type- Parameters:
registry- the registry to register withname- the evaluator namedisplayName- the display name shown in the UIdefinition- description of what the evaluator measuresevaluatorFn- the evaluation function- Returns:
- the created evaluator
-
define
public static <O> Evaluator<O> define(Registry registry, String name, String displayName, String definition, boolean isBilled, Class<O> optionsClass, EvaluatorFn<O> evaluatorFn) Defines a new evaluator with full options and registers it with the registry.- Type Parameters:
O- the options type- Parameters:
registry- the registry to register withname- the evaluator namedisplayName- the display name shown in the UIdefinition- description of what the evaluator measuresisBilled- whether using this evaluator incurs costsoptionsClass- the class for evaluator-specific optionsevaluatorFn- the evaluation function- Returns:
- the created evaluator
-
getName
Description copied from interface:ActionReturns the name of the action.- Specified by:
getNamein interfaceAction<EvalRequest,List<EvalResponse>, Void> - Returns:
- the action name
-
getType
Description copied from interface:ActionReturns the type of the action.- Specified by:
getTypein interfaceAction<EvalRequest,List<EvalResponse>, Void> - Returns:
- the action type
-
getDesc
Description copied from interface:ActionReturns the descriptor of the action containing metadata, schemas, etc.- Specified by:
getDescin interfaceAction<EvalRequest,List<EvalResponse>, Void> - Returns:
- the action descriptor
-
getInfo
Gets the evaluator info.- Returns:
- the evaluator info
-
run
Description copied from interface:ActionRuns the action with the given input.- Specified by:
runin interfaceAction<EvalRequest,List<EvalResponse>, Void> - Parameters:
ctx- the action contextinput- the input to the action- Returns:
- the output of the action
- Throws:
GenkitException- if the action fails
-
run
public List<EvalResponse> run(ActionContext ctx, EvalRequest input, Consumer<Void> streamCallback) throws GenkitException Description copied from interface:ActionRuns the action with the given input and streaming callback.- Specified by:
runin interfaceAction<EvalRequest,List<EvalResponse>, Void> - Parameters:
ctx- the action contextinput- the input to the actionstreamCallback- callback for receiving streaming chunks, may be null- Returns:
- the output of the action
- Throws:
GenkitException- if the action fails
-
runJson
public com.fasterxml.jackson.databind.JsonNode runJson(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) throws GenkitException Description copied from interface:ActionRuns the action with JSON input and returns JSON output.- Specified by:
runJsonin interfaceAction<EvalRequest,List<EvalResponse>, Void> - Parameters:
ctx- the action contextinput- the JSON inputstreamCallback- callback for receiving streaming JSON chunks, may be null- Returns:
- the JSON output
- Throws:
GenkitException- if the action fails
-
runJsonWithTelemetry
public ActionRunResult<com.fasterxml.jackson.databind.JsonNode> runJsonWithTelemetry(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) throws GenkitException Description copied from interface:ActionRuns the action with JSON input and returns the result with telemetry information.- Specified by:
runJsonWithTelemetryin interfaceAction<EvalRequest,List<EvalResponse>, Void> - Parameters:
ctx- the action contextinput- the JSON inputstreamCallback- callback for receiving streaming JSON chunks, may be null- Returns:
- the action result including telemetry data
- Throws:
GenkitException- if the action fails
-
register
Description copied from interface:RegisterableRegisters this primitive with the given registry.- Specified by:
registerin interfaceRegisterable- Parameters:
registry- the registry to register with
-
getInputSchema
Description copied from interface:ActionReturns the JSON schema for the action's input type.- Specified by:
getInputSchemain interfaceAction<EvalRequest,List<EvalResponse>, Void> - Returns:
- the input schema as a map, or null if not defined
-
getOutputSchema
Description copied from interface:ActionReturns the JSON schema for the action's output type.- Specified by:
getOutputSchemain interfaceAction<EvalRequest,List<EvalResponse>, Void> - Returns:
- the output schema as a map, or null if not defined
-
getMetadata
Description copied from interface:ActionReturns additional metadata for the action.- Specified by:
getMetadatain interfaceAction<EvalRequest,List<EvalResponse>, Void> - Returns:
- the metadata map
-