From 051551edb7caf4b287d2d214e26d9bf921eb9d0f Mon Sep 17 00:00:00 2001 From: Zamuldinov Nikita Date: Tue, 10 Mar 2026 10:02:58 +0300 Subject: [PATCH] fix: use platform-appropriate user data dir instead of /tmp for vector store paths The default vector store path was hardcoded to /tmp/{provider}, which fails in: - macOS LaunchAgents: /tmp cleared on reboot, limited permissions - Linux systemd: may have noexec restrictions or private /tmp namespaces - Windows: /tmp does not exist - Docker: /tmp is ephemeral unless mounted as a volume Replace with a cross-platform user data directory: - Linux/macOS: $XDG_DATA_HOME or ~/.local/share/mem0/{provider} - Windows: %APPDATA%/mem0/{provider} This follows the XDG Base Directory Specification on Linux and the conventional APPDATA path on Windows, making mem0 work reliably in all deployment environments without requiring explicit path config. Closes #4279 --- mem0/vector_stores/configs.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mem0/vector_stores/configs.py b/mem0/vector_stores/configs.py index 32459dddc..ab9ad8af3 100644 --- a/mem0/vector_stores/configs.py +++ b/mem0/vector_stores/configs.py @@ -1,3 +1,6 @@ +import os + +from pathlib import Path from typing import Dict, Optional from pydantic import BaseModel, Field, model_validator @@ -61,7 +64,18 @@ class VectorStoreConfig(BaseModel): # also check if path in allowed kays for pydantic model, and whether config extra fields are allowed if "path" not in config and "path" in config_class.__annotations__: - config["path"] = f"/tmp/{provider}" + # Use a platform-appropriate user data directory instead of /tmp, which is + # ephemeral on many systems and may be unwritable in service/restricted environments. + # Preference order: XDG_DATA_HOME (Linux) → APPDATA (Windows) → ~/.local/share + xdg = os.environ.get("XDG_DATA_HOME") + app_data = os.environ.get("APPDATA") + if xdg: + base = Path(xdg) + elif app_data: + base = Path(app_data) + else: + base = Path.home() / ".local" / "share" + config["path"] = str(base / "mem0" / provider) self.config = config_class(**config) return self