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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! Basic usage example for mem0-rust.
//!
//! This example demonstrates how to create a Memory instance,
//! add memories, and search for them.
use mem0_rust::{AddOptions, Memory, MemoryConfig, SearchOptions};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a memory instance with default config (in-memory store, mock embedder)
let config = MemoryConfig::default();
let memory = Memory::new(config).await?;
// Add some memories for a user
let user_id = "alice";
memory
.add(
"I love programming in Rust",
AddOptions {
user_id: Some(user_id.to_string()),
infer: false, // Disable LLM inference for this example
..Default::default()
},
)
.await?;
memory
.add(
"My favorite food is pizza",
AddOptions {
user_id: Some(user_id.to_string()),
infer: false,
..Default::default()
},
)
.await?;
memory
.add(
"I work as a software engineer",
AddOptions {
user_id: Some(user_id.to_string()),
infer: false,
..Default::default()
},
)
.await?;
// Search for relevant memories
let results = memory
.search(
"programming languages",
SearchOptions {
user_id: Some(user_id.to_string()),
limit: Some(3),
..Default::default()
},
)
.await?;
println!("Top results:");
for result in &results.results {
println!(
"- {} (score: {:.3})",
result.record.content, result.score
);
}
Ok(())
}