pub struct RetentionPolicy { /* private fields */ }Expand description
Ordered set of retention rules.
Rules are evaluated in insertion order. The first RetentionDecision::Keep
or RetentionDecision::Drop wins; RetentionDecision::Defer falls
through to later rules and finally to default_decision.
§Example
use rig_memory_policy::{
FrameKind, FrameMetadata, RetentionCandidate, RetentionDecision,
RetentionPolicy,
};
let metadata = FrameMetadata {
schema_version: 1,
kind: FrameKind::CompactionSummary,
conversation_id: "conv-1".into(),
chat_role: "assistant".into(),
dedup_key: "abc".into(),
scope: Some("tenant-a".into()),
};
let policy = RetentionPolicy::new()
.keep_summaries()
.drop_written_before(1_700_000_000_000)
.default_decision(RetentionDecision::Drop);
let decision = policy.evaluate(
RetentionCandidate::new(&metadata).with_written_at_unix_ms(1_600_000_000_000),
);
assert_eq!(decision, RetentionDecision::Keep);Implementations§
Source§impl RetentionPolicy
impl RetentionPolicy
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct an empty policy with RetentionDecision::Defer as default.
Sourcepub fn rule(self, rule: RetentionRule) -> Self
pub fn rule(self, rule: RetentionRule) -> Self
Add a custom rule to the end of the policy.
Sourcepub fn default_decision(self, decision: RetentionDecision) -> Self
pub fn default_decision(self, decision: RetentionDecision) -> Self
Set the decision returned when no rule matches.
Sourcepub fn keep_summaries(self) -> Self
pub fn keep_summaries(self) -> Self
Keep all compaction summaries.
Sourcepub fn keep_demoted_messages(self) -> Self
pub fn keep_demoted_messages(self) -> Self
Keep all demoted messages.
Sourcepub fn keep_scope(self, scope: impl Into<Scope>) -> Self
pub fn keep_scope(self, scope: impl Into<Scope>) -> Self
Keep candidates in the required exact scope.
Sourcepub fn keep_recent(self, min_sequence: u64) -> Self
pub fn keep_recent(self, min_sequence: u64) -> Self
Keep candidates at or above min_sequence.
Sourcepub fn drop_written_before(self, older_than_unix_ms: u64) -> Self
pub fn drop_written_before(self, older_than_unix_ms: u64) -> Self
Drop candidates written before older_than_unix_ms.
Sourcepub fn drop_last_accessed_before(self, older_than_unix_ms: u64) -> Self
pub fn drop_last_accessed_before(self, older_than_unix_ms: u64) -> Self
Drop candidates last accessed before older_than_unix_ms.
Sourcepub fn drop_outside_scope(
self,
required_scope: Option<impl Into<Scope>>,
) -> Self
pub fn drop_outside_scope( self, required_scope: Option<impl Into<Scope>>, ) -> Self
Drop candidates outside an exact scope. None keeps only unscoped
candidates from matching this rule.
Sourcepub fn keep_label(self, label: impl Into<String>) -> Self
pub fn keep_label(self, label: impl Into<String>) -> Self
Keep candidates with the provided host-defined retention label.
Sourcepub fn drop_label(self, label: impl Into<String>) -> Self
pub fn drop_label(self, label: impl Into<String>) -> Self
Drop candidates with the provided host-defined retention label.
Sourcepub fn evaluate(&self, candidate: RetentionCandidate<'_>) -> RetentionDecision
pub fn evaluate(&self, candidate: RetentionCandidate<'_>) -> RetentionDecision
Evaluate one candidate against this policy.
Sourcepub fn rules(&self) -> &[RetentionRule]
pub fn rules(&self) -> &[RetentionRule]
Return the ordered rules in this policy.
Trait Implementations§
Source§impl Clone for RetentionPolicy
impl Clone for RetentionPolicy
Source§fn clone(&self) -> RetentionPolicy
fn clone(&self) -> RetentionPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RetentionPolicy
impl Debug for RetentionPolicy
Source§impl Default for RetentionPolicy
impl Default for RetentionPolicy
Source§impl PartialEq for RetentionPolicy
impl PartialEq for RetentionPolicy
Source§fn eq(&self, other: &RetentionPolicy) -> bool
fn eq(&self, other: &RetentionPolicy) -> bool
self and other values to be equal, and is used by ==.