use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
#[derive(Debug, Clone, Deserialize, JsonSchema)]
#[schemars(transform = crate::schema::strip_int_formats)]
pub struct Link {
pub target: u64,
pub relation: String,
}
#[derive(Debug, Clone, Serialize, JsonSchema)]
#[schemars(transform = crate::schema::strip_int_formats)]
pub struct Recollection {
pub id: u64,
pub score: f32,
pub content: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Map<String, Value>>,
}
#[derive(Debug, Clone, Copy, Deserialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum ColumnOp {
Eq,
Ne,
Lt,
Le,
Gt,
Ge,
}
impl ColumnOp {
#[cfg(feature = "persistence")]
#[must_use]
pub(crate) fn as_sql(self) -> &'static str {
match self {
Self::Eq => "=",
Self::Ne => "!=",
Self::Lt => "<",
Self::Le => "<=",
Self::Gt => ">",
Self::Ge => ">=",
}
}
}
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct ColumnFilter {
pub field: String,
pub op: ColumnOp,
pub value: Value,
}
#[derive(Debug, Clone, Copy)]
pub struct FusionOptions {
pub hops: usize,
pub graph_boost: f64,
pub pool: Option<usize>,
}
impl Default for FusionOptions {
fn default() -> Self {
Self {
hops: 2,
graph_boost: 0.15,
pool: None,
}
}
}
impl FusionOptions {
#[must_use]
pub fn from_knobs(hops: Option<usize>, graph_boost: Option<f64>, pool: Option<usize>) -> Self {
let defaults = Self::default();
Self {
hops: crate::limits::clamp_hops(hops.unwrap_or(defaults.hops)),
graph_boost: graph_boost.unwrap_or(defaults.graph_boost),
pool: pool
.map(crate::limits::clamp_recall_limit)
.or(defaults.pool),
}
}
#[must_use]
pub fn sanitized(mut self) -> Self {
if !self.graph_boost.is_finite() {
self.graph_boost = Self::default().graph_boost;
}
self
}
}
#[derive(Debug, Clone, Serialize, JsonSchema)]
#[schemars(transform = crate::schema::strip_int_formats)]
pub struct MemoryNode {
pub id: u64,
pub content: String,
pub hop: usize,
}
#[derive(Debug, Clone, Serialize, JsonSchema)]
#[schemars(transform = crate::schema::strip_int_formats)]
pub struct MemoryEdge {
pub from: u64,
pub to: u64,
pub relation: String,
}
#[derive(Debug, Clone, Default, Serialize, JsonSchema)]
pub struct Explanation {
pub nodes: Vec<MemoryNode>,
pub edges: Vec<MemoryEdge>,
}