use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryConfig {
pub embedder: EmbedderConfig,
pub vector_store: VectorStoreConfig,
pub llm: Option<LLMConfig>,
pub history_db_path: Option<PathBuf>,
pub custom_prompts: Option<CustomPrompts>,
pub reranker: Option<RerankerConfig>,
pub version: String,
pub collection_name: String,
}
impl Default for MemoryConfig {
fn default() -> Self {
Self {
embedder: EmbedderConfig::default(),
vector_store: VectorStoreConfig::default(),
llm: None,
history_db_path: None,
custom_prompts: None,
reranker: None,
version: "1.1".to_string(),
collection_name: "mem0".to_string(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "provider", rename_all = "lowercase")]
pub enum EmbedderConfig {
Mock(MockEmbedderConfig),
#[cfg(feature = "openai")]
OpenAI(OpenAIEmbedderConfig),
#[cfg(feature = "ollama")]
Ollama(OllamaEmbedderConfig),
HuggingFace(HuggingFaceEmbedderConfig),
}
impl Default for EmbedderConfig {
fn default() -> Self {
EmbedderConfig::Mock(MockEmbedderConfig::default())
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MockEmbedderConfig {
pub dimensions: usize,
}
impl Default for MockEmbedderConfig {
fn default() -> Self {
Self { dimensions: 128 }
}
}
#[cfg(feature = "openai")]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OpenAIEmbedderConfig {
pub api_key: Option<String>,
pub model: String,
pub dimensions: Option<usize>,
pub base_url: Option<String>,
}
#[cfg(feature = "openai")]
impl Default for OpenAIEmbedderConfig {
fn default() -> Self {
Self {
api_key: None,
model: "text-embedding-3-small".to_string(),
dimensions: Some(1536),
base_url: None,
}
}
}
#[cfg(feature = "ollama")]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OllamaEmbedderConfig {
pub model: String,
pub base_url: String,
pub dimensions: usize,
}
#[cfg(feature = "ollama")]
impl Default for OllamaEmbedderConfig {
fn default() -> Self {
Self {
model: "nomic-embed-text".to_string(),
base_url: "http://localhost:11434".to_string(),
dimensions: 768,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HuggingFaceEmbedderConfig {
pub api_key: Option<String>,
pub model: String,
pub dimensions: usize,
pub api_url: Option<String>,
}
impl Default for HuggingFaceEmbedderConfig {
fn default() -> Self {
Self {
api_key: None,
model: "sentence-transformers/all-MiniLM-L6-v2".to_string(),
dimensions: 384,
api_url: None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "provider", rename_all = "lowercase")]
pub enum VectorStoreConfig {
Memory(MemoryStoreConfig),
#[cfg(feature = "qdrant")]
Qdrant(QdrantConfig),
#[cfg(feature = "postgres")]
Postgres(PostgresConfig),
#[cfg(feature = "redis")]
Redis(RedisConfig),
}
impl Default for VectorStoreConfig {
fn default() -> Self {
VectorStoreConfig::Memory(MemoryStoreConfig::default())
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct MemoryStoreConfig {
pub max_entries: Option<usize>,
}
#[cfg(feature = "qdrant")]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QdrantConfig {
pub url: String,
pub api_key: Option<String>,
pub collection_name: String,
pub dimensions: usize,
pub distance: DistanceMetric,
}
#[cfg(feature = "qdrant")]
impl Default for QdrantConfig {
fn default() -> Self {
Self {
url: "http://localhost:6334".to_string(),
api_key: None,
collection_name: "mem0".to_string(),
dimensions: 1536,
distance: DistanceMetric::Cosine,
}
}
}
#[cfg(feature = "postgres")]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PostgresConfig {
pub connection_url: String,
pub table_name: String,
pub dimensions: usize,
}
#[cfg(feature = "postgres")]
impl Default for PostgresConfig {
fn default() -> Self {
Self {
connection_url: "postgres://localhost/mem0".to_string(),
table_name: "memories".to_string(),
dimensions: 1536,
}
}
}
#[cfg(feature = "redis")]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RedisConfig {
pub url: String,
pub index_name: String,
pub dimensions: usize,
}
#[cfg(feature = "redis")]
impl Default for RedisConfig {
fn default() -> Self {
Self {
url: "redis://localhost:6379".to_string(),
index_name: "mem0_idx".to_string(),
dimensions: 1536,
}
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum DistanceMetric {
#[default]
Cosine,
Euclidean,
DotProduct,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "provider", rename_all = "lowercase")]
pub enum LLMConfig {
#[cfg(feature = "openai")]
OpenAI(OpenAILLMConfig),
#[cfg(feature = "ollama")]
Ollama(OllamaLLMConfig),
#[cfg(feature = "anthropic")]
Anthropic(AnthropicConfig),
}
#[cfg(feature = "openai")]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OpenAILLMConfig {
pub api_key: Option<String>,
pub model: String,
pub temperature: f32,
pub max_tokens: Option<u32>,
pub base_url: Option<String>,
}
#[cfg(feature = "openai")]
impl Default for OpenAILLMConfig {
fn default() -> Self {
Self {
api_key: None,
model: "gpt-4o-mini".to_string(),
temperature: 0.0,
max_tokens: Some(1500),
base_url: None,
}
}
}
#[cfg(feature = "ollama")]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OllamaLLMConfig {
pub model: String,
pub base_url: String,
pub temperature: f32,
}
#[cfg(feature = "ollama")]
impl Default for OllamaLLMConfig {
fn default() -> Self {
Self {
model: "llama3.2".to_string(),
base_url: "http://localhost:11434".to_string(),
temperature: 0.0,
}
}
}
#[cfg(feature = "anthropic")]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AnthropicConfig {
pub api_key: Option<String>,
pub model: String,
pub temperature: f32,
pub max_tokens: u32,
}
#[cfg(feature = "anthropic")]
impl Default for AnthropicConfig {
fn default() -> Self {
Self {
api_key: None,
model: "claude-3-haiku-20240307".to_string(),
temperature: 0.0,
max_tokens: 1500,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct CustomPrompts {
pub fact_extraction: Option<String>,
pub memory_update: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "provider", rename_all = "lowercase")]
pub enum RerankerConfig {
Cohere(CohereRerankerConfig),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CohereRerankerConfig {
pub api_key: Option<String>,
pub model: String,
}
impl Default for CohereRerankerConfig {
fn default() -> Self {
Self {
api_key: None,
model: "rerank-english-v3.0".to_string(),
}
}
}