pub struct ConversationMemory { /* private fields */ }Expand description
Thread-safe conversation memory that stores and retrieves turns per customer.
Internally uses Arc<RwLock<HashMap<String, Vec<ConversationTurn>>>> so it can
be shared across async tasks and agent threads.
Implementations§
Source§impl ConversationMemory
impl ConversationMemory
Sourcepub async fn record_turn(
&self,
customer_id: &str,
session_id: &str,
role: &str,
content: &str,
metadata: HashMap<String, String>,
)
pub async fn record_turn( &self, customer_id: &str, session_id: &str, role: &str, content: &str, metadata: HashMap<String, String>, )
Record a conversation turn for a customer.
Sourcepub async fn record_turn_with_timestamp(
&self,
customer_id: &str,
session_id: &str,
role: &str,
content: &str,
metadata: HashMap<String, String>,
timestamp: DateTime<Utc>,
)
pub async fn record_turn_with_timestamp( &self, customer_id: &str, session_id: &str, role: &str, content: &str, metadata: HashMap<String, String>, timestamp: DateTime<Utc>, )
Record a turn with an explicit timestamp (useful for tests and imports).
Sourcepub async fn get_context(
&self,
customer_id: &str,
max_turns: usize,
) -> Vec<ConversationTurn>
pub async fn get_context( &self, customer_id: &str, max_turns: usize, ) -> Vec<ConversationTurn>
Retrieve the last max_turns turns for a customer across all sessions.
Returns turns in chronological order (oldest first among the returned set).
Sourcepub async fn summarize_history(&self, customer_id: &str) -> String
pub async fn summarize_history(&self, customer_id: &str) -> String
Build a text summary of all interactions for a customer.
Returns a human-readable multi-line summary including session count, turn count, time range, and a condensed transcript.
Sourcepub async fn get_sessions(&self, customer_id: &str) -> Vec<String>
pub async fn get_sessions(&self, customer_id: &str) -> Vec<String>
Get a list of distinct session IDs for a customer.
Sourcepub async fn search_history(
&self,
customer_id: &str,
query: &str,
) -> Vec<ConversationTurn>
pub async fn search_history( &self, customer_id: &str, query: &str, ) -> Vec<ConversationTurn>
Case-insensitive keyword search across all turns for a customer.
Returns turns whose content contains the query substring.
Sourcepub async fn build_profile(&self, customer_id: &str) -> Option<CustomerProfile>
pub async fn build_profile(&self, customer_id: &str) -> Option<CustomerProfile>
Build a CustomerProfile from the stored conversation history.
Topics are extracted as the most frequent non-stopword tokens. Sentiment is inferred from metadata if present, otherwise defaults to “neutral”.
Sourcepub async fn customer_count(&self) -> usize
pub async fn customer_count(&self) -> usize
Return the total number of customers tracked.
Sourcepub async fn customer_ids(&self) -> Vec<String>
pub async fn customer_ids(&self) -> Vec<String>
Return all customer IDs.
Sourcepub async fn turn_count(&self, customer_id: &str) -> usize
pub async fn turn_count(&self, customer_id: &str) -> usize
Return total turn count for a customer.
Trait Implementations§
Source§impl Clone for ConversationMemory
impl Clone for ConversationMemory
Source§fn clone(&self) -> ConversationMemory
fn clone(&self) -> ConversationMemory
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more