Class Experiment.Builder
- Enclosing class:
Experiment
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets an asynchronous task that produces aTaskResultas aCompletableFuture.autoCloseReporter(boolean autoCloseReporter) Controls whetherExperiment.run()closes the reporter after the run completes.build()Builds the experiment.Sets the dataset.description(String description) Sets the description.Adds a single evaluator to the experiment.evaluators(List<Evaluator> evaluators) Adds multiple evaluators to the experiment.measuredTask(MeasuredTask measuredTask) Sets a measured task that carriesCallMetricsthrough to eachItemResult.Adds a metadata entry to the experiment.Adds multiple metadata entries to the experiment.Sets the experiment name.parallelism(int parallelism) Sets the level of parallelism for running the experiment.Sets the reporter for this experiment.runs(int runs) Sets the number of times to run the experiment.Sets the task.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
name
Sets the experiment name.- Parameters:
name- the experiment name- Returns:
- this builder
-
description
Sets the description.- Parameters:
description- The experiment's description.- Returns:
- builder
-
dataset
Sets the dataset.- Parameters:
dataset- The dataset to use for the experiment.- Returns:
- builder
-
task
Sets the task.- Parameters:
task- The task to generate outputs from examples.- Returns:
- builder
-
measuredTask
Sets a measured task that carriesCallMetricsthrough to eachItemResult.- Parameters:
measuredTask- The task to generate outputs and metrics from examples.- Returns:
- builder
-
asyncTask
Sets an asynchronous task that produces aTaskResultas aCompletableFuture.When an async task is set, the experiment runs through a dedicated non-blocking execution path that bounds the number of in-flight invocations to
parallelism(int)using a semaphore. This path takes precedence overparallelism(int)-based parallel and sequential execution. Per-item failures are isolated exactly as in the synchronous paths: a failed future becomes a failedItemResultand the run continues.An async task is mutually exclusive with a synchronous
task(Task)ormeasuredTask(MeasuredTask): configuring both fails fast inbuild().- Parameters:
asyncTask- the asynchronous task to generate outputs and metrics from examples- Returns:
- builder
-
evaluator
Adds a single evaluator to the experiment.- Parameters:
evaluator- The evaluator to add.- Returns:
- builder
-
evaluators
Adds multiple evaluators to the experiment.- Parameters:
evaluators- The list of evaluators to add.- Returns:
- builder
-
metadata
Adds a metadata entry to the experiment.- Parameters:
key- The metadata key.value- The metadata value.- Returns:
- builder
-
metadata
Adds multiple metadata entries to the experiment.- Parameters:
metadata- The map of metadata entries to add.- Returns:
- builder
-
reporter
Sets the reporter for this experiment.The reporter is called during experiment execution to report results to an external system. If not set, a no-op reporter is used.
- Parameters:
reporter- the reporter to use- Returns:
- builder
-
parallelism
Sets the level of parallelism for running the experiment.When parallelism is greater than 1, examples within each run are processed concurrently using a fixed thread pool. Default is 1 for sequential execution.
Ensure your task implementation is thread-safe when using parallelism.
- Parameters:
parallelism- the number of examples to process in parallel, must be at least 1- Returns:
- builder
- Throws:
IllegalArgumentException- if parallelism is less than 1
-
runs
Sets the number of times to run the experiment.Running an experiment multiple times helps reduce variance from LLM non-determinism and provides statistical confidence in the results. Results are automatically aggregated across runs.
Runs execute sequentially while parallelism applies within each run.
- Parameters:
runs- the number of experiment runs, must be at least 1- Returns:
- builder
- Throws:
IllegalArgumentException- if runs is less than 1
-
autoCloseReporter
Controls whetherExperiment.run()closes the reporter after the run completes.When enabled, the reporter is closed (in addition to being flushed) once all runs finish. Defaults to
falseso the caller retains ownership of the reporter lifecycle.- Parameters:
autoCloseReporter- whether to close the reporter after the run completes- Returns:
- builder
-
build
Builds the experiment.- Returns:
- a new experiment
- Throws:
IllegalStateException- if dataset or task is not set, the dataset has no examples, or no evaluators were added
-