pub struct MemoryService<E: Embedder> { /* private fields */ }Expand description
Local-first agent memory backed by a single VelesDB instance.
Generic over the Embedder so production can use an on-device model while
tests use a deterministic, network-free one.
Implementations§
Source§impl<E: Embedder> MemoryService<E>
impl<E: Embedder> MemoryService<E>
Sourcepub fn open<P: AsRef<Path>>(path: P, embedder: E) -> Result<Self, MemoryError>
pub fn open<P: AsRef<Path>>(path: P, embedder: E) -> Result<Self, MemoryError>
Open (or create) a memory store at path, using embedder for text
vectorization. The store never leaves this directory.
§Errors
Returns MemoryError if the store cannot be opened or the agent
memory cannot be initialized for the embedder’s dimension.
Sourcepub fn remember(
&self,
fact: &str,
links: &[Link],
metadata: Option<&Metadata>,
) -> Result<u64, MemoryError>
pub fn remember( &self, fact: &str, links: &[Link], metadata: Option<&Metadata>, ) -> Result<u64, MemoryError>
Remember a fact, optionally tagging it with structured metadata
(ColumnStore facet) and linking it to existing memories (graph facet).
Returns the stable id of the fact (idempotent on identical content).
Link targets are validated to exist before the fact is stored, so a bad link never leaves the fact half-written.
§Errors
Returns MemoryError::EmptyFact for empty/whitespace facts,
MemoryError::ReservedKey if metadata names a reserved key
(content or any _veles_-prefixed system key),
MemoryError::UnknownMemory if a link points at a missing memory,
or a storage error if persistence fails.
Sourcepub fn remember_extracted<X: Extractor>(
&self,
text: &str,
extractor: &X,
metadata: Option<&Metadata>,
) -> Result<Vec<u64>, MemoryError>
pub fn remember_extracted<X: Extractor>( &self, text: &str, extractor: &X, metadata: Option<&Metadata>, ) -> Result<Vec<u64>, MemoryError>
Remember a passage of raw text by running it through an Extractor
and storing every fact it yields, auto-wiring the fact↔entity graph.
This is the commodity on top of Self::remember’s bring-your-own-links
core: each extracted fact is stored (tagged with metadata), each salient
topic becomes a deduplicated hub memory, and every fact is linked to its
topics with a bidirectional about/mentions edge. Two facts sharing a
topic therefore become reachable from one another, so Self::why has a
real graph to traverse with no manual relate().
Entity hubs are content-addressed, so the same topic seen across many calls collapses onto one hub. Returns the ids of the stored facts (entity hubs excluded), in extraction order.
§Errors
Returns MemoryError::EmptyFact for empty/whitespace text,
MemoryError::Extract if extraction fails, MemoryError::ReservedKey
if metadata names a reserved key, or a storage error if persistence fails.
Sourcepub fn recall(
&self,
query: &str,
k: usize,
filter: Option<&Metadata>,
) -> Result<Vec<Recollection>, MemoryError>
pub fn recall( &self, query: &str, k: usize, filter: Option<&Metadata>, ) -> Result<Vec<Recollection>, MemoryError>
Recall up to k memories semantically similar to query (vector facet),
optionally narrowed to an exact-match metadata filter (ColumnStore
facet) — e.g. { "project": "veles", "status": "resolved" }.
A highly selective filter may return fewer than k hits even when more
matches exist — raise k for fuller coverage with a narrow filter.
Entity hubs created by Self::remember_extracted are never returned:
they are internal graph scaffolding, not facts the caller stored.
§Errors
Returns MemoryError if the semantic query fails.
Sourcepub fn recall_where(
&self,
query: &str,
k: usize,
filters: &[ColumnFilter],
) -> Result<Vec<Recollection>, MemoryError>
pub fn recall_where( &self, query: &str, k: usize, filters: &[ColumnFilter], ) -> Result<Vec<Recollection>, MemoryError>
Fused recall: semantic NEAR search combined with structured
ColumnStore predicates over metadata columns — ranges and comparisons,
not just the equality of Self::recall. One query spanning the vector
and column facets (e.g. “most similar facts with timestamp in this
window”), which a vector-only or equality-only recall cannot express.
Filter values are bound as query parameters (never interpolated), so they cannot inject; filter field names are validated to be plain identifiers. Results come back in similarity order.
§Errors
Returns MemoryError::InvalidFilter if a filter field is not a plain
identifier, MemoryError::Embed if the query cannot be embedded, or a
storage error if the query fails. An empty query or k == 0 yields [].
Sourcepub fn relate(
&self,
from: u64,
to: u64,
relation: &str,
) -> Result<u64, MemoryError>
pub fn relate( &self, from: u64, to: u64, relation: &str, ) -> Result<u64, MemoryError>
Create a typed edge from -> to. Returns the edge id.
Both endpoints are validated to exist first, so the tool reports an
unknown id as client input (UnknownMemory) rather than a generic
storage fault — and the graph never gains an edge dangling off a memory
that was never stored.
§Errors
Returns MemoryError::UnknownMemory if either endpoint is missing, or
a storage error if the edge cannot be created.
Sourcepub fn why(
&self,
decision: &str,
max_hops: usize,
filter: Option<&Metadata>,
) -> Result<Explanation, MemoryError>
pub fn why( &self, decision: &str, max_hops: usize, filter: Option<&Metadata>, ) -> Result<Explanation, MemoryError>
Explain a decision: find the best-matching memory (optionally scoped to
a metadata filter, e.g. the current project), then walk its typed links
up to max_hops away — fusing the vector, ColumnStore, and graph facets.
Returns an empty Explanation when nothing matches the decision.
§Errors
Returns MemoryError if recall or graph traversal fails.
Auto Trait Implementations§
impl<E> !Freeze for MemoryService<E>
impl<E> !RefUnwindSafe for MemoryService<E>
impl<E> !UnwindSafe for MemoryService<E>
impl<E> Send for MemoryService<E>where
E: Send,
impl<E> Sync for MemoryService<E>where
E: Sync,
impl<E> Unpin for MemoryService<E>where
E: Unpin,
impl<E> UnsafeUnpin for MemoryService<E>where
E: UnsafeUnpin,
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> 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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);