use crate::client::new_id;
use crate::wire::types::{
ActAs, EncodeRequest, ForgetMode, ForgetRequest, MemoryKindWire, RecallRequest,
RecallScopeWire, WaitMode, WireMemoryId,
};
#[derive(Clone, Debug)]
pub struct EncodeBuilder {
text: String,
session_id: u64,
occurred_at_unix_nanos: Option<u64>,
act_as: Option<ActAs>,
wait: WaitMode,
allow_duplicates: bool,
}
impl EncodeBuilder {
#[must_use]
pub fn new(text: impl Into<String>) -> Self {
Self {
text: text.into(),
session_id: 0,
occurred_at_unix_nanos: None,
act_as: None,
wait: WaitMode::Ack,
allow_duplicates: false,
}
}
#[must_use]
pub fn wait(mut self, wait: WaitMode) -> Self {
self.wait = wait;
self
}
#[must_use]
pub fn wait_derived(mut self) -> Self {
self.wait = WaitMode::Derived;
self
}
#[must_use]
pub fn act_as(mut self, namespace: impl Into<String>, space_id: impl Into<String>) -> Self {
self.act_as = Some(ActAs {
namespace: namespace.into(),
space_id: space_id.into(),
grant: 0,
});
self
}
#[must_use]
pub fn session(mut self, session_id: u64) -> Self {
self.session_id = session_id;
self
}
#[must_use]
pub fn occurred_at(mut self, occurred_at_unix_nanos: u64) -> Self {
self.occurred_at_unix_nanos = Some(occurred_at_unix_nanos);
self
}
#[must_use]
pub fn allow_duplicates(mut self, allow: bool) -> Self {
self.allow_duplicates = allow;
self
}
#[must_use]
pub fn build(self) -> EncodeRequest {
EncodeRequest {
text: self.text,
session_id: self.session_id,
request_id: new_id(),
txn_id: None,
occurred_at_unix_nanos: self.occurred_at_unix_nanos,
act_as: self.act_as,
wait: self.wait,
allow_duplicates: self.allow_duplicates,
}
}
}
#[derive(Clone, Debug)]
pub struct RecallBuilder {
cue_text: String,
subject_name: String,
max_results: u32,
confidence_threshold: f32,
session_filter: Option<Vec<u64>>,
age_bound_unix_nanos: Option<u64>,
as_of_record_time_unix_nanos: Option<u64>,
kind_filter: Option<Vec<MemoryKindWire>>,
salience_floor: f32,
include_edges: bool,
include_graph: bool,
include_text: bool,
trace: bool,
act_as: Option<ActAs>,
scope: RecallScopeWire,
}
impl RecallBuilder {
#[must_use]
pub fn new(cue_text: impl Into<String>) -> Self {
Self {
cue_text: cue_text.into(),
subject_name: String::new(),
max_results: 10,
confidence_threshold: 0.0,
session_filter: None,
age_bound_unix_nanos: None,
as_of_record_time_unix_nanos: None,
kind_filter: None,
salience_floor: 0.0,
include_edges: true,
include_graph: false,
include_text: true,
trace: false,
act_as: None,
scope: RecallScopeWire::Space,
}
}
#[must_use]
pub fn scope(mut self, scope: RecallScopeWire) -> Self {
self.scope = scope;
self
}
#[must_use]
pub fn act_as(mut self, namespace: impl Into<String>, space_id: impl Into<String>) -> Self {
self.act_as = Some(ActAs {
namespace: namespace.into(),
space_id: space_id.into(),
grant: 0,
});
self
}
#[must_use]
pub fn subject(mut self, name: impl Into<String>) -> Self {
self.subject_name = name.into();
self
}
#[must_use]
pub fn max_results(mut self, max_results: u32) -> Self {
self.max_results = max_results;
self
}
#[must_use]
pub fn as_of(mut self, as_of_record_time_unix_nanos: u64) -> Self {
self.as_of_record_time_unix_nanos = Some(as_of_record_time_unix_nanos);
self
}
#[must_use]
pub fn confidence_threshold(mut self, threshold: f32) -> Self {
self.confidence_threshold = threshold;
self
}
#[must_use]
pub fn sessions(mut self, sessions: Vec<u64>) -> Self {
self.session_filter = Some(sessions);
self
}
#[must_use]
pub fn kinds(mut self, kinds: Vec<MemoryKindWire>) -> Self {
self.kind_filter = Some(kinds);
self
}
#[must_use]
pub fn salience_floor(mut self, floor: f32) -> Self {
self.salience_floor = floor;
self
}
#[must_use]
pub fn include_edges(mut self, include: bool) -> Self {
self.include_edges = include;
self
}
#[must_use]
pub fn include_graph(mut self, include: bool) -> Self {
self.include_graph = include;
self
}
#[must_use]
pub fn trace(mut self, trace: bool) -> Self {
self.trace = trace;
self
}
#[must_use]
pub fn include_text(mut self, include: bool) -> Self {
self.include_text = include;
self
}
#[must_use]
pub fn build(self) -> RecallRequest {
RecallRequest {
cue_text: self.cue_text,
subject_name: self.subject_name,
max_results: self.max_results,
confidence_threshold: self.confidence_threshold,
session_filter: self.session_filter,
age_bound_unix_nanos: self.age_bound_unix_nanos,
as_of_record_time_unix_nanos: self.as_of_record_time_unix_nanos,
kind_filter: self.kind_filter,
salience_floor: self.salience_floor,
include_edges: self.include_edges,
include_graph: self.include_graph,
include_text: self.include_text,
request_id: Some(new_id()),
txn_id: None,
trace: self.trace,
act_as: self.act_as,
scope: self.scope,
}
}
}
#[derive(Clone, Debug)]
pub struct ForgetBuilder {
memory_id: WireMemoryId,
mode: ForgetMode,
act_as: Option<ActAs>,
}
impl ForgetBuilder {
#[must_use]
pub fn new(memory_id: WireMemoryId) -> Self {
Self {
memory_id,
mode: ForgetMode::Soft,
act_as: None,
}
}
#[must_use]
pub fn act_as(mut self, namespace: impl Into<String>, space_id: impl Into<String>) -> Self {
self.act_as = Some(ActAs {
namespace: namespace.into(),
space_id: space_id.into(),
grant: 0,
});
self
}
#[must_use]
pub fn hard(mut self) -> Self {
self.mode = ForgetMode::Hard;
self
}
#[must_use]
pub fn mode(mut self, mode: ForgetMode) -> Self {
self.mode = mode;
self
}
#[must_use]
pub fn build(self) -> ForgetRequest {
ForgetRequest {
memory_id: self.memory_id,
mode: self.mode,
request_id: new_id(),
txn_id: None,
act_as: self.act_as,
}
}
}