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
impl SemanticStore
Sourcepub fn store(
&self,
key: impl Into<String> + Debug,
value: impl Into<String> + Debug,
tags: Vec<String>,
) -> Result<(), AgentRuntimeError>
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.
Sourcepub fn store_with_embedding(
&self,
key: impl Into<String> + Debug,
value: impl Into<String> + Debug,
tags: Vec<String>,
embedding: Vec<f32>,
) -> Result<(), AgentRuntimeError>
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.
Sourcepub fn retrieve(
&self,
tags: &[&str],
) -> Result<Vec<(String, String)>, AgentRuntimeError>
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.
Sourcepub fn retrieve_similar(
&self,
query_embedding: &[f32],
top_k: usize,
) -> Result<Vec<(String, String, f32)>, AgentRuntimeError>
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.
Sourcepub fn len(&self) -> Result<usize, AgentRuntimeError>
pub fn len(&self) -> Result<usize, AgentRuntimeError>
Return the total number of stored entries.
Sourcepub fn is_empty(&self) -> Result<bool, AgentRuntimeError>
pub fn is_empty(&self) -> Result<bool, AgentRuntimeError>
Return true if no entries have been stored.
Trait Implementations§
Source§impl Clone for SemanticStore
impl Clone for SemanticStore
Source§fn clone(&self) -> SemanticStore
fn clone(&self) -> SemanticStore
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SemanticStore
impl Debug for SemanticStore
Auto Trait Implementations§
impl Freeze for SemanticStore
impl RefUnwindSafe for SemanticStore
impl Send for SemanticStore
impl Sync for SemanticStore
impl Unpin for SemanticStore
impl UnsafeUnpin for SemanticStore
impl UnwindSafe for SemanticStore
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
Mutably borrows from an owned value. Read more