Skip to main content

SemanticStore

Struct SemanticStore 

Source
pub struct SemanticStore { /* private fields */ }
Expand description

Stores semantic (fact-based) knowledge as tagged key-value pairs.

§Guarantees

  • Thread-safe via Arc<Mutex<_>>
  • Retrieval by tag intersection
  • Optional vector-based similarity search via stored embeddings

Implementations§

Source§

impl SemanticStore

Source

pub fn new() -> Self

Create a new empty semantic store.

Source

pub fn store( &self, key: impl Into<String> + Debug, value: impl Into<String> + Debug, tags: Vec<String>, ) -> Result<(), AgentRuntimeError>

Store a key-value pair with associated tags.

Source

pub fn store_with_embedding( &self, key: impl Into<String> + Debug, value: impl Into<String> + Debug, tags: Vec<String>, embedding: Vec<f32>, ) -> Result<(), AgentRuntimeError>

Store a key-value pair with an embedding vector for similarity search.

§Errors

Returns Err(AgentRuntimeError::Memory) if embedding is empty or dimension mismatches.

Source

pub fn retrieve( &self, tags: &[&str], ) -> Result<Vec<(String, String)>, AgentRuntimeError>

Retrieve all entries that contain all of the given tags.

If tags is empty, returns all entries.

Source

pub fn retrieve_similar( &self, query_embedding: &[f32], top_k: usize, ) -> Result<Vec<(String, String, f32)>, AgentRuntimeError>

Retrieve top-k entries by cosine similarity to query_embedding.

Only entries that were stored with an embedding (via store_with_embedding) are considered. Returns (key, value, similarity) sorted by descending similarity.

Returns Err(AgentRuntimeError::Memory) if query_embedding dimension mismatches.

Source

pub fn update( &self, key: &str, new_value: impl Into<String>, ) -> Result<bool, AgentRuntimeError>

Update the value of the first entry whose key matches key.

Returns Ok(true) if found and updated, Ok(false) if not found.

Source

pub fn retrieve_by_key( &self, key: &str, ) -> Result<Option<(String, Vec<String>)>, AgentRuntimeError>

Look up a single entry by its exact key.

Returns Ok(Some((value, tags))) if found, Ok(None) if not.

Source

pub fn contains(&self, key: &str) -> Result<bool, AgentRuntimeError>

Return true if an entry with the given key is stored.

Source

pub fn clear(&self) -> Result<(), AgentRuntimeError>

Remove all entries.

Source

pub fn count_by_tag(&self, tag: &str) -> Result<usize, AgentRuntimeError>

Count entries that contain tag (case-sensitive).

Source

pub fn list_tags(&self) -> Result<Vec<String>, AgentRuntimeError>

Return all unique tags present across all stored entries, in sorted order.

Source

pub fn remove_entries_with_tag( &self, tag: &str, ) -> Result<usize, AgentRuntimeError>

Remove all entries that have the given tag.

Returns the number of entries removed.

Source

pub fn most_common_tag(&self) -> Result<Option<String>, AgentRuntimeError>

Return the tag that appears most often across all entries.

Returns None if there are no tagged entries.

Source

pub fn keys_for_tag(&self, tag: &str) -> Result<Vec<String>, AgentRuntimeError>

Return the keys of all entries that have the given tag.

Source

pub fn unique_tags(&self) -> Result<Vec<String>, AgentRuntimeError>

Return a sorted list of every distinct tag appearing across all entries.

Source

pub fn tag_count(&self) -> Result<usize, AgentRuntimeError>

Return the number of distinct tags across all stored entries.

Equivalent to list_tags()?.len() but avoids allocating the full tag list.

Source

pub fn entry_count_with_embedding(&self) -> Result<usize, AgentRuntimeError>

Return the number of entries that have an associated embedding vector.

Source

pub fn get_value(&self, key: &str) -> Result<Option<String>, AgentRuntimeError>

Return the stored value for the first entry whose key matches key, or None if no such entry exists.

Simpler alternative to retrieve_by_key when only the value is needed and tags are not required.

Source

pub fn get_tags( &self, key: &str, ) -> Result<Option<Vec<String>>, AgentRuntimeError>

Return the tags for the first entry whose key matches key.

Returns None if no entry with that key exists.

Source

pub fn keys_with_tag(&self, tag: &str) -> Result<Vec<String>, AgentRuntimeError>

Return all entry keys that contain tag (case-sensitive).

Source

pub fn tags_for( &self, key: &str, ) -> Result<Option<Vec<String>>, AgentRuntimeError>

Return the tags associated with the first entry matching key, or None if no entry with that key exists.

Source

pub fn has_key(&self, key: &str) -> Result<bool, AgentRuntimeError>

Return true if at least one entry with the given key exists.

Source

pub fn value_for(&self, key: &str) -> Result<Option<String>, AgentRuntimeError>

Return the value string of the first entry whose key matches key, or None if no such entry exists.

Source

pub fn entries_without_tags(&self) -> Result<usize, AgentRuntimeError>

Return the number of entries that have no tags.

Source

pub fn most_tagged_key(&self) -> Result<Option<String>, AgentRuntimeError>

Return the keys of all entries that have no tags. Return the key of the entry with the most tags, or None if the store is empty.

Source

pub fn rename_tag( &self, old_tag: &str, new_tag: &str, ) -> Result<usize, AgentRuntimeError>

Return the count of entries whose value contains substring. Rename old_tag to new_tag across all entries.

Returns the number of entries that were modified.

Source

pub fn count_matching_value( &self, substring: &str, ) -> Result<usize, AgentRuntimeError>

Return the count of entries whose value contains substring.

Source

pub fn entries_with_no_tags(&self) -> Result<Vec<String>, AgentRuntimeError>

Return the keys of all entries that have no tags.

Source

pub fn avg_tag_count_per_entry(&self) -> Result<f64, AgentRuntimeError>

Return the mean number of tags per entry.

Returns 0.0 when the store is empty.

Source

pub fn most_recent_key(&self) -> Result<Option<String>, AgentRuntimeError>

Return the key of the most recently inserted entry, or None if empty.

Source

pub fn oldest_key(&self) -> Result<Option<String>, AgentRuntimeError>

Return the key of the earliest inserted entry, or None if empty.

Source

pub fn remove_by_key(&self, key: &str) -> Result<usize, AgentRuntimeError>

Remove all entries whose key equals key.

Returns the number of entries removed.

Source

pub fn entry_count_with_tag( &self, tag: &str, ) -> Result<usize, AgentRuntimeError>

Return the number of entries that include tag in their tag list.

Source

pub fn list_keys(&self) -> Result<Vec<String>, AgentRuntimeError>

Return all stored entry keys in insertion order.

Duplicate keys (if any) will appear multiple times.

Source

pub fn keys(&self) -> Result<Vec<String>, AgentRuntimeError>

Return all stored entry keys in insertion order.

Alias for list_keys using more idiomatic naming.

Source

pub fn values(&self) -> Result<Vec<String>, AgentRuntimeError>

Return the stored value for every entry, in insertion order.

Source

pub fn keys_matching( &self, pattern: &str, ) -> Result<Vec<String>, AgentRuntimeError>

Return all keys that contain pattern as a substring (case-insensitive).

Useful for prefix/contains searches without loading values.

Source

pub fn update_value( &self, key: &str, new_value: impl Into<String>, ) -> Result<bool, AgentRuntimeError>

Update the stored value of the first entry whose key matches key.

Returns Ok(true) if found and updated, Ok(false) if not found.

Source

pub fn to_map(&self) -> Result<HashMap<String, String>, AgentRuntimeError>

Return all stored entries as a HashMap<key, value>.

Useful for serialization or bulk inspection. Tags and embeddings are discarded; use iter() / retrieve_by_key when those are needed.

Source

pub fn update_tags( &self, key: &str, new_tags: Vec<String>, ) -> Result<bool, AgentRuntimeError>

Update the tags of the first entry whose key matches key.

Returns Ok(true) if found and updated, Ok(false) if not found.

Source

pub fn total_value_bytes(&self) -> Result<usize, AgentRuntimeError>

Return the sum of byte lengths of all stored values.

Returns 0 if no entries have been stored.

Source

pub fn avg_value_bytes(&self) -> Result<f64, AgentRuntimeError>

Return the mean byte length of all stored values.

Returns 0.0 if no entries have been stored.

Source

pub fn max_value_bytes(&self) -> Result<usize, AgentRuntimeError>

Return the byte length of the longest stored value.

Returns 0 if no entries have been stored.

Source

pub fn min_value_bytes(&self) -> Result<usize, AgentRuntimeError>

Return the byte length of the shortest stored value.

Returns 0 if no entries have been stored.

Source

pub fn all_keys(&self) -> Result<Vec<String>, AgentRuntimeError>

Return all stored keys in ascending sorted order.

Source

pub fn len(&self) -> Result<usize, AgentRuntimeError>

Return the total number of stored entries.

Source

pub fn is_empty(&self) -> Result<bool, AgentRuntimeError>

Return true if no entries have been stored.

Source

pub fn count(&self) -> Result<usize, AgentRuntimeError>

Return the number of stored entries.

Alias for len using conventional naming.

Source

pub fn remove(&self, key: &str) -> Result<bool, AgentRuntimeError>

Remove the first entry with key key.

Returns Ok(true) if an entry was found and removed, Ok(false) if no entry with that key exists.

Trait Implementations§

Source§

impl Clone for SemanticStore

Source§

fn clone(&self) -> SemanticStore

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SemanticStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SemanticStore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more