1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! MemoryStore trait — semantic memory indexing for discarded conversation history.
//!
//! Implementations live in `meerkat-memory` crate.
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
/// Metadata associated with an indexed memory entry.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryMetadata {
/// The session ID this memory originated from.
pub session_id: crate::types::SessionId,
/// Turn number within the session.
pub turn: Option<u32>,
/// When the memory was indexed.
pub indexed_at: crate::time_compat::SystemTime,
}
/// A memory search result.
#[derive(Debug, Clone)]
pub struct MemoryResult {
/// The text content of the memory.
pub content: String,
/// Metadata about the source.
pub metadata: MemoryMetadata,
/// Relevance score (0.0 = no match, 1.0 = perfect match).
pub score: f32,
}
/// Semantic memory store for indexing and searching conversation history.
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait MemoryStore: Send + Sync {
/// Index text content with associated metadata.
async fn index(&self, content: &str, metadata: MemoryMetadata) -> Result<(), MemoryStoreError>;
/// Search for memories matching the query.
async fn search(
&self,
query: &str,
limit: usize,
) -> Result<Vec<MemoryResult>, MemoryStoreError>;
}
/// Errors from memory store operations.
#[derive(Debug, thiserror::Error)]
pub enum MemoryStoreError {
#[error("Embedding error: {0}")]
Embedding(String),
#[error("Index error: {0}")]
Index(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
}