1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub struct LlmConfig {
5 pub base_url: String,
6 pub api_key: String,
7 pub model: String,
8 #[serde(default = "default_temperature")]
9 pub temperature: f32,
10 #[serde(default = "default_max_tokens")]
11 pub max_tokens: u32,
12}
13
14fn default_temperature() -> f32 {
15 0.0
16}
17
18fn default_max_tokens() -> u32 {
19 1000
20}
21
22impl Default for LlmConfig {
23 fn default() -> Self {
24 Self {
25 base_url: "https://api.openai.com/v1".into(),
26 api_key: String::new(),
27 model: "gpt-4.1-nano".into(),
28 temperature: default_temperature(),
29 max_tokens: default_max_tokens(),
30 }
31 }
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct EmbeddingConfig {
36 pub base_url: String,
37 pub api_key: String,
38 pub model: String,
39 #[serde(default = "default_embedding_dims")]
40 pub dims: usize,
41}
42
43fn default_embedding_dims() -> usize {
44 1536
45}
46
47impl Default for EmbeddingConfig {
48 fn default() -> Self {
49 Self {
50 base_url: "https://api.openai.com/v1".into(),
51 api_key: String::new(),
52 model: "text-embedding-3-small".into(),
53 dims: default_embedding_dims(),
54 }
55 }
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct VectorConfig {
60 #[serde(default = "default_provider")]
61 pub provider: String,
62 #[serde(default = "default_collection")]
63 pub collection_name: String,
64 #[serde(default = "default_embedding_dims")]
65 pub dims: usize,
66 pub upstash_url: Option<String>,
67 pub upstash_token: Option<String>,
68}
69
70fn default_provider() -> String {
71 "flat".into()
72}
73
74fn default_collection() -> String {
75 "mem7_memories".into()
76}
77
78impl Default for VectorConfig {
79 fn default() -> Self {
80 Self {
81 provider: default_provider(),
82 collection_name: default_collection(),
83 dims: default_embedding_dims(),
84 upstash_url: None,
85 upstash_token: None,
86 }
87 }
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
91pub struct HistoryConfig {
92 #[serde(default = "default_history_path")]
93 pub db_path: String,
94}
95
96fn default_history_path() -> String {
97 "mem7_history.db".into()
98}
99
100impl Default for HistoryConfig {
101 fn default() -> Self {
102 Self {
103 db_path: default_history_path(),
104 }
105 }
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize, Default)]
109pub struct MemoryEngineConfig {
110 #[serde(default)]
111 pub llm: LlmConfig,
112 #[serde(default)]
113 pub embedding: EmbeddingConfig,
114 #[serde(default)]
115 pub vector: VectorConfig,
116 #[serde(default)]
117 pub history: HistoryConfig,
118 pub custom_fact_extraction_prompt: Option<String>,
119 pub custom_update_memory_prompt: Option<String>,
120}