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
This commit is contained in:
committed by
utkarsh240799
parent
7e3b727528
commit
051551edb7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user