Skip to content

Commit d3777b0

Browse files
fix(core): default fastembed cache to ~/.basic-memory/fastembed_cache
FastEmbed's own default of /tmp/fastembed_cache is ephemeral in sandboxed runtimes like Codex CLI where /tmp is wiped between invocations, causing ONNXRuntimeError: NO_SUCHFILE on every subsequent semantic search or sync. Add _default_fastembed_cache_dir() that mirrors the existing data_dir_path logic (honors BASIC_MEMORY_CONFIG_DIR for isolated test environments) and use it as default_factory for semantic_embedding_cache_dir. The field stays str | None so users can explicitly set null to restore FastEmbed's own default. Fixes #741. Related to #681. Co-authored-by: Drew Cain <groksrc@users.noreply.github.com> Signed-off-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
1 parent 8f2b25f commit d3777b0

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

src/basic_memory/config.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ def _default_semantic_search_enabled() -> bool:
5050
)
5151

5252

53+
def _default_fastembed_cache_dir() -> str:
54+
"""Default FastEmbed model cache to ~/.basic-memory/fastembed_cache.
55+
56+
FastEmbed's own default is <system-temp>/fastembed_cache (e.g. /tmp/fastembed_cache on
57+
Linux), which is ephemeral in sandboxed runtimes like Codex CLI and can disappear between
58+
invocations, causing ONNXRuntimeError: NO_SUCHFILE on every subsequent run.
59+
60+
By defaulting to a path inside the Basic Memory data directory we stay consistent with
61+
where other app state lives and ensure the ONNX model survives across sessions.
62+
Honors BASIC_MEMORY_CONFIG_DIR so isolated test environments remain self-contained.
63+
"""
64+
if config_dir := os.getenv("BASIC_MEMORY_CONFIG_DIR"):
65+
return str(Path(config_dir) / "fastembed_cache")
66+
home = os.getenv("HOME", str(Path.home()))
67+
return str(Path(home) / DATA_DIR_NAME / "fastembed_cache")
68+
69+
5370
@dataclass
5471
class ProjectConfig:
5572
"""Configuration for a specific basic-memory project."""
@@ -221,8 +238,11 @@ def __init__(self, **data: Any) -> None: ...
221238
le=16,
222239
)
223240
semantic_embedding_cache_dir: str | None = Field(
224-
default=None,
225-
description="Optional cache directory for FastEmbed model artifacts.",
241+
default_factory=_default_fastembed_cache_dir,
242+
description="Cache directory for FastEmbed model artifacts. Defaults to "
243+
"~/.basic-memory/fastembed_cache to avoid FastEmbed's ephemeral /tmp default, "
244+
"which breaks MCP in sandboxed runtimes (e.g. Codex CLI). "
245+
"Set to null to use FastEmbed's own default.",
226246
)
227247
semantic_embedding_threads: int | None = Field(
228248
default=None,

0 commit comments

Comments
 (0)