pub struct SemanticMemory {
pub token_counter: Arc<TokenCounter>,
/* private fields */
}Fields§
§token_counter: Arc<TokenCounter>Implementations§
Source§impl SemanticMemory
impl SemanticMemory
Sourcepub async fn new(
sqlite_path: &str,
qdrant_url: &str,
provider: AnyProvider,
embedding_model: &str,
) -> Result<Self, MemoryError>
pub async fn new( sqlite_path: &str, qdrant_url: &str, provider: AnyProvider, embedding_model: &str, ) -> Result<Self, MemoryError>
Create a new SemanticMemory instance with default hybrid search weights (0.7/0.3).
Qdrant connection is best-effort: if unavailable, semantic search is disabled.
§Errors
Returns an error if SQLite cannot be initialized.
Sourcepub async fn with_weights(
sqlite_path: &str,
qdrant_url: &str,
provider: AnyProvider,
embedding_model: &str,
vector_weight: f64,
keyword_weight: f64,
) -> Result<Self, MemoryError>
pub async fn with_weights( sqlite_path: &str, qdrant_url: &str, provider: AnyProvider, embedding_model: &str, vector_weight: f64, keyword_weight: f64, ) -> Result<Self, MemoryError>
Create a new SemanticMemory with custom vector/keyword weights for hybrid search.
§Errors
Returns an error if SQLite cannot be initialized.
Sourcepub async fn with_weights_and_pool_size(
sqlite_path: &str,
qdrant_url: &str,
provider: AnyProvider,
embedding_model: &str,
vector_weight: f64,
keyword_weight: f64,
pool_size: u32,
) -> Result<Self, MemoryError>
pub async fn with_weights_and_pool_size( sqlite_path: &str, qdrant_url: &str, provider: AnyProvider, embedding_model: &str, vector_weight: f64, keyword_weight: f64, pool_size: u32, ) -> Result<Self, MemoryError>
Create a new SemanticMemory with custom weights and configurable pool size.
§Errors
Returns an error if SQLite cannot be initialized.
Sourcepub fn with_ranking_options(
self,
temporal_decay_enabled: bool,
temporal_decay_half_life_days: u32,
mmr_enabled: bool,
mmr_lambda: f32,
) -> Self
pub fn with_ranking_options( self, temporal_decay_enabled: bool, temporal_decay_half_life_days: u32, mmr_enabled: bool, mmr_lambda: f32, ) -> Self
Configure temporal decay and MMR re-ranking options.
Sourcepub async fn with_sqlite_backend(
sqlite_path: &str,
provider: AnyProvider,
embedding_model: &str,
vector_weight: f64,
keyword_weight: f64,
) -> Result<Self, MemoryError>
pub async fn with_sqlite_backend( sqlite_path: &str, provider: AnyProvider, embedding_model: &str, vector_weight: f64, keyword_weight: f64, ) -> Result<Self, MemoryError>
Create a SemanticMemory using the SQLite-embedded vector backend.
§Errors
Returns an error if SQLite cannot be initialized.
Sourcepub async fn with_sqlite_backend_and_pool_size(
sqlite_path: &str,
provider: AnyProvider,
embedding_model: &str,
vector_weight: f64,
keyword_weight: f64,
pool_size: u32,
) -> Result<Self, MemoryError>
pub async fn with_sqlite_backend_and_pool_size( sqlite_path: &str, provider: AnyProvider, embedding_model: &str, vector_weight: f64, keyword_weight: f64, pool_size: u32, ) -> Result<Self, MemoryError>
Create a SemanticMemory using the SQLite-embedded vector backend with configurable pool size.
§Errors
Returns an error if SQLite cannot be initialized.
Sourcepub async fn remember(
&self,
conversation_id: ConversationId,
role: &str,
content: &str,
) -> Result<MessageId, MemoryError>
pub async fn remember( &self, conversation_id: ConversationId, role: &str, content: &str, ) -> Result<MessageId, MemoryError>
Save a message to SQLite and optionally embed and store in Qdrant.
Returns the message ID assigned by SQLite.
§Errors
Returns an error if the SQLite save fails. Embedding failures are logged but not
propagated.
Sourcepub async fn remember_with_parts(
&self,
conversation_id: ConversationId,
role: &str,
content: &str,
parts_json: &str,
) -> Result<(MessageId, bool), MemoryError>
pub async fn remember_with_parts( &self, conversation_id: ConversationId, role: &str, content: &str, parts_json: &str, ) -> Result<(MessageId, bool), MemoryError>
Save a message with pre-serialized parts JSON to SQLite and optionally embed in Qdrant.
Returns (message_id, embedding_stored) tuple where embedding_stored is true if
an embedding was successfully generated and stored in Qdrant.
§Errors
Returns an error if the SQLite save fails.
Sourcepub async fn save_only(
&self,
conversation_id: ConversationId,
role: &str,
content: &str,
parts_json: &str,
) -> Result<MessageId, MemoryError>
pub async fn save_only( &self, conversation_id: ConversationId, role: &str, content: &str, parts_json: &str, ) -> Result<MessageId, MemoryError>
Save a message to SQLite without generating an embedding.
Use this when embedding is intentionally skipped (e.g. autosave disabled for assistant).
§Errors
Returns an error if the SQLite save fails.
Sourcepub async fn recall(
&self,
query: &str,
limit: usize,
filter: Option<SearchFilter>,
) -> Result<Vec<RecalledMessage>, MemoryError>
pub async fn recall( &self, query: &str, limit: usize, filter: Option<SearchFilter>, ) -> Result<Vec<RecalledMessage>, MemoryError>
Recall relevant messages using hybrid search (vector + FTS5 keyword).
When Qdrant is available, runs both vector and keyword searches, then merges results using weighted scoring. When Qdrant is unavailable, falls back to FTS5-only keyword search.
§Errors
Returns an error if embedding generation, Qdrant search, or FTS5 query fails.
Sourcepub async fn has_embedding(
&self,
message_id: MessageId,
) -> Result<bool, MemoryError>
pub async fn has_embedding( &self, message_id: MessageId, ) -> Result<bool, MemoryError>
Check whether an embedding exists for a given message ID.
§Errors
Returns an error if the SQLite query fails.
Sourcepub async fn embed_missing(&self) -> Result<usize, MemoryError>
pub async fn embed_missing(&self) -> Result<usize, MemoryError>
Embed all messages that do not yet have embeddings.
Returns the count of successfully embedded messages.
§Errors
Returns an error if collection initialization or database query fails. Individual embedding failures are logged but do not stop processing.
Sourcepub async fn store_session_summary(
&self,
conversation_id: ConversationId,
summary_text: &str,
) -> Result<(), MemoryError>
pub async fn store_session_summary( &self, conversation_id: ConversationId, summary_text: &str, ) -> Result<(), MemoryError>
Store a session summary into the dedicated zeph_session_summaries Qdrant collection.
§Errors
Returns an error if embedding or Qdrant storage fails.
Sourcepub async fn search_session_summaries(
&self,
query: &str,
limit: usize,
exclude_conversation_id: Option<ConversationId>,
) -> Result<Vec<SessionSummaryResult>, MemoryError>
pub async fn search_session_summaries( &self, query: &str, limit: usize, exclude_conversation_id: Option<ConversationId>, ) -> Result<Vec<SessionSummaryResult>, MemoryError>
Search session summaries from other conversations.
§Errors
Returns an error if embedding or Qdrant search fails.
Sourcepub fn sqlite(&self) -> &SqliteStore
pub fn sqlite(&self) -> &SqliteStore
Access the underlying SqliteStore for operations that don’t involve semantics.
Sourcepub async fn is_vector_store_connected(&self) -> bool
pub async fn is_vector_store_connected(&self) -> bool
Check if the vector store backend is reachable.
Performs a real health check (Qdrant gRPC ping or SQLite query)
instead of just checking whether the client was created.
Sourcepub fn has_vector_store(&self) -> bool
pub fn has_vector_store(&self) -> bool
Check if a vector store client is configured (may not be connected).
Sourcepub async fn message_count(
&self,
conversation_id: ConversationId,
) -> Result<i64, MemoryError>
pub async fn message_count( &self, conversation_id: ConversationId, ) -> Result<i64, MemoryError>
Sourcepub async fn unsummarized_message_count(
&self,
conversation_id: ConversationId,
) -> Result<i64, MemoryError>
pub async fn unsummarized_message_count( &self, conversation_id: ConversationId, ) -> Result<i64, MemoryError>
Sourcepub async fn load_summaries(
&self,
conversation_id: ConversationId,
) -> Result<Vec<Summary>, MemoryError>
pub async fn load_summaries( &self, conversation_id: ConversationId, ) -> Result<Vec<Summary>, MemoryError>
Sourcepub async fn summarize(
&self,
conversation_id: ConversationId,
message_count: usize,
) -> Result<Option<i64>, MemoryError>
pub async fn summarize( &self, conversation_id: ConversationId, message_count: usize, ) -> Result<Option<i64>, MemoryError>
Generate a summary of the oldest unsummarized messages.
Returns Ok(None) if there are not enough messages to summarize.
§Errors
Returns an error if LLM call or database operation fails.
Sourcepub async fn search_key_facts(
&self,
query: &str,
limit: usize,
) -> Result<Vec<String>, MemoryError>
pub async fn search_key_facts( &self, query: &str, limit: usize, ) -> Result<Vec<String>, MemoryError>
Search key facts extracted from conversation summaries.
§Errors
Returns an error if embedding or Qdrant search fails.
Auto Trait Implementations§
impl !Freeze for SemanticMemory
impl !RefUnwindSafe for SemanticMemory
impl Send for SemanticMemory
impl Sync for SemanticMemory
impl Unpin for SemanticMemory
impl UnsafeUnpin for SemanticMemory
impl !UnwindSafe for SemanticMemory
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request