use mem0_rust::{AddOptions, Memory, MemoryConfig};
use std::path::PathBuf;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let history_db = PathBuf::from("history.db");
if history_db.exists() {
std::fs::remove_file(&history_db)?;
}
let config = MemoryConfig {
history_db_path: Some(history_db.clone()),
..Default::default()
};
let memory = Memory::new(config).await?;
println!("Adding memory...");
let result = memory
.add(
"Initial memory content",
AddOptions::for_user("alice").raw(),
)
.await?;
let id = result.results[0].id.to_string();
println!("Added memory ID: {}", id);
println!("Updating memory...");
memory.update(&id, "Updated memory content").await?;
let history = memory.history(&id).await?;
println!("\nHistory for {}:", id);
for entry in history {
println!("- [{}] {:?} (New: '{}', Old: '{:?}')",
entry.timestamp,
entry.event,
entry.new_content,
entry.previous_content
);
}
let _ = std::fs::remove_file(history_db);
Ok(())
}