pub struct IntentGraph {
pub v: u32,
pub built_from_ts: u64,
pub rev: u64,
pub intents: Vec<Intent>,
pub model: Option<String>,
/* private fields */
}Expand description
The usage-ranking read model — a set of query clusters with capability edges.
Built either in-process by the local learner or offline by Ratel Cloud; both
emit the shape in protocol/v1. Attach one to a registry to add the usage
arm to its ranking.
Fields§
§v: u32Schema version. Always [GRAPH_VERSION] for a graph this build accepts.
built_from_ts: u64Epoch-millis of the newest event folded in. Provenance only — it says how current the graph is, and nothing reads it during ranking.
rev: u64Monotonic write counter, bumped once on every mutation (Self::observe,
a centroid rebuild). Nothing reads it during ranking; it exists for the
caller’s storage layer, which owns persistence (the graph is in-process
only). Two uses: save-when-changed — persist only when rev differs
from the last saved value; and stale-base detection — before
overwriting a stored graph, compare its rev to the one you loaded, and
if it advanced another writer got there first (single-writer is the
supported model; this makes a clobber detectable, not merged). Carried
in the wire form; an older graph without it loads as 0 and continues up.
intents: Vec<Intent>The clusters. Order is not significant.
model: Option<String>Fingerprint of the embedding model the centroids were built with, or
None for a lexically-grown graph that has none.
Centroids are only comparable to a query embedded by the same model.
This lets a consumer detect a model swap (GraphModelStatus) instead of
cosine-ing across incompatible vector spaces. Stamped when the first
centroid is grown, or by a producer (e.g. Ratel Cloud) that builds
centroids offline.
Implementations§
Source§impl IntentGraph
impl IntentGraph
Sourcepub fn from_json(json: &str) -> Result<Self, IntentGraphError>
pub fn from_json(json: &str) -> Result<Self, IntentGraphError>
Parse a graph from its JSON wire form.
§Errors
IntentGraphError::Malformed if the bytes are not the expected shape,
or IntentGraphError::UnsupportedVersion if v is not 1.
Sourcepub fn empty() -> Self
pub fn empty() -> Self
An empty graph at the current version — the starting state of a learner.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the graph holds no clusters — the cold-start state, in which it contributes no arm to any query.
Sourcepub fn rev(&self) -> u64
pub fn rev(&self) -> u64
The write counter — see Self::rev. Snapshot it after each save; a
later value means unsaved learning, or another writer moved ahead of you.
Sourcepub fn labeled(&self) -> Vec<Intent>
pub fn labeled(&self) -> Vec<Intent>
The clusters with their display fields materialized against the graph as it is now.
Labels are derived rather than stored for two reasons. c-TF-IDF ranks a term by how rare it is across the other clusters, so a value computed when a cluster was last written goes stale as soon as the graph grows. And computing them on write meant re-tokenizing every member of every cluster on every invocation — for strings ranking never reads.
The whole-corpus token index (per_cluster, global, avg) is built
once here and shared by every cluster’s c-TF-IDF; building it inside
each call made this quadratic in cluster count.
Trait Implementations§
Source§impl Clone for IntentGraph
impl Clone for IntentGraph
Source§fn clone(&self) -> IntentGraph
fn clone(&self) -> IntentGraph
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 IntentGraph
impl Debug for IntentGraph
Source§impl Default for IntentGraph
impl Default for IntentGraph
Source§impl<'de> Deserialize<'de> for IntentGraph
impl<'de> Deserialize<'de> for IntentGraph
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for IntentGraph
impl PartialEq for IntentGraph
Source§impl Serialize for IntentGraph
Serializing materializes the derived display fields, so the wire form always
carries labels computed against the graph being written — never a stale
snapshot from whenever a cluster last happened to change.
impl Serialize for IntentGraph
Serializing materializes the derived display fields, so the wire form always carries labels computed against the graph being written — never a stale snapshot from whenever a cluster last happened to change.
impl StructuralPartialEq for IntentGraph
Auto Trait Implementations§
impl !Freeze for IntentGraph
impl RefUnwindSafe for IntentGraph
impl Send for IntentGraph
impl Sync for IntentGraph
impl Unpin for IntentGraph
impl UnsafeUnpin for IntentGraph
impl UnwindSafe for IntentGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more