Skip to main content

SemanticMemory

Struct SemanticMemory 

Source
pub struct SemanticMemory {
    pub token_counter: Arc<TokenCounter>,
    /* private fields */
}

Fields§

§token_counter: Arc<TokenCounter>

Implementations§

Source§

impl SemanticMemory

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn sqlite(&self) -> &SqliteStore

Access the underlying SqliteStore for operations that don’t involve semantics.

Source

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.

Source

pub fn has_vector_store(&self) -> bool

Check if a vector store client is configured (may not be connected).

Source

pub async fn message_count( &self, conversation_id: ConversationId, ) -> Result<i64, MemoryError>

Count messages in a conversation.

§Errors

Returns an error if the query fails.

Source

pub async fn unsummarized_message_count( &self, conversation_id: ConversationId, ) -> Result<i64, MemoryError>

Count messages not yet covered by any summary.

§Errors

Returns an error if the query fails.

Source

pub async fn load_summaries( &self, conversation_id: ConversationId, ) -> Result<Vec<Summary>, MemoryError>

Load all summaries for a conversation.

§Errors

Returns an error if the query fails.

Source

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.

Source

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§

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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