Skip to main content

kowalski_core/memory/
mod.rs

1pub mod consolidation;
2pub mod episodic;
3pub mod helpers;
4pub mod semantic;
5#[cfg(feature = "postgres")]
6pub mod semantic_pg;
7#[cfg(test)]
8mod tests;
9pub mod working;
10
11#[cfg(feature = "postgres")]
12pub use semantic_pg::PostgresSemanticStore;
13
14use async_trait::async_trait;
15use serde::{Deserialize, Serialize};
16
17use crate::error::KowalskiError;
18
19/// Represents a single unit of memory, which could be a message, a fact, or a summary.
20#[derive(Serialize, Deserialize, Clone, Debug)]
21pub struct MemoryUnit {
22    pub id: String, // Unique identifier for this memory unit
23    pub timestamp: u64,
24    pub content: String,
25    pub embedding: Option<Vec<f32>>,
26}
27
28/// The core trait for any memory system in Kowalski.
29/// Defines the essential operations for storing and retrieving memories.
30#[async_trait]
31pub trait MemoryProvider {
32    /// Adds a memory unit to the store.
33    async fn add(&mut self, memory: MemoryUnit) -> Result<(), KowalskiError>;
34
35    /// Retrieves a set of memories based on a query, limited to retrieval_limit.
36    async fn retrieve(
37        &self,
38        query: &str,
39        retrieval_limit: usize,
40    ) -> Result<Vec<MemoryUnit>, KowalskiError>;
41
42    /// A more advanced retrieval method using a structured query.
43    async fn search(&self, query: MemoryQuery) -> Result<Vec<MemoryUnit>, KowalskiError>;
44}
45
46/// A structured query for more advanced memory retrieval.
47#[derive(Debug, Clone)]
48pub struct MemoryQuery {
49    pub text_query: String,
50    pub vector_query: Option<Vec<f32>>,
51    pub top_k: usize,
52}