trulens.core.sampling¶
trulens.core.sampling
¶
Sampling configuration and controller for online evaluation.
Controls which records are evaluated during automatic post-ingest evaluation.
Does not affect explicit compute_metrics / compute_now calls.
.. note::
Counters (throttle window, daily cost accumulator) are per-process.
Multiple workers each enforce their own limits, so effective maximums
scale with the number of processes. The daily cost budget resets at
UTC midnight and enforcement lags by roughly
concurrency * cost_per_eval, making it a soft cap.
Classes¶
EvalDecisionReason
¶
Why a record was or was not evaluated.
Attributes¶
EVALUATED
class-attribute
instance-attribute
¶
EVALUATED = 'evaluated'
Record was sampled and evaluated normally.
NOT_CONFIGURED
class-attribute
instance-attribute
¶
NOT_CONFIGURED = 'not_configured'
Sampling does not apply to this record (app not in per-app config).
The record is evaluated normally β this is not a skip reason.
NOT_SAMPLED
class-attribute
instance-attribute
¶
NOT_SAMPLED = 'not_sampled'
Record was skipped by the probabilistic sampler.
THROTTLED
class-attribute
instance-attribute
¶
THROTTLED = 'throttled'
Record was skipped because the throttle window is saturated.
OVER_BUDGET
class-attribute
instance-attribute
¶
OVER_BUDGET = 'over_budget'
Record was skipped because the daily cost budget is exhausted.
SamplingConfig
¶
Bases: BaseModel
Immutable configuration for online-evaluation sampling.
| ATTRIBUTE | DESCRIPTION |
|---|---|
sample_rate |
Probability (0.0 -- 1.0) that a record is evaluated.
Can also be a |
throttle |
Maximum evaluations per minute. |
cost_budget |
Daily USD cap for evaluation cost. |
Attributes¶
sample_rate
class-attribute
instance-attribute
¶
Probability of evaluating a record.
float-- a single global rate applied to every app.dict[str, float]-- per-app rates keyed by app name. Records from apps not in the dict are not evaluated.
throttle
class-attribute
instance-attribute
¶
Max evaluations per minute (None = unlimited).
SamplingController
¶
Mutable state manager for sampling decisions.
Holds the token-bucket (throttle), daily cost accumulator, and evaluated/skipped counters. All public methods are thread-safe: the lock is held only for bookkeeping, never across an evaluation call.
This class is designed to be substitutable in tests -- construct one directly and pass it wherever a controller is expected.