Skip to content

fix(embeddings): respect HERMES_HOME for fastembed cache default#366

Open
mxfng wants to merge 2 commits into
AxDSan:mainfrom
mxfng:fix/fastembed-cache-respect-hermes-home
Open

fix(embeddings): respect HERMES_HOME for fastembed cache default#366
mxfng wants to merge 2 commits into
AxDSan:mainfrom
mxfng:fix/fastembed-cache-respect-hermes-home

Conversation

@mxfng

@mxfng mxfng commented Jun 19, 2026

Copy link
Copy Markdown

The MNEMOSYNE_FASTEMBED_CACHE_DIR override (added in fix/ci-embedding-model-cache) lets CI redirect the fastembed model cache, but its default still hardcodes ~/.hermes and ignores HERMES_HOME.

Problem

Users who relocate HERMES_HOME — e.g. to ~/.config/hermes for XDG cleanliness — end up with a stray ~/.hermes/cache/fastembed directory holding ~64MB of BGE model weights, separate from the rest of their Hermes state (config, db, logs, mnemosyne data), all of which correctly live under $HERMES_HOME.

Because the cache path is passed as an explicit cache_dir= argument to TextEmbedding(), no fastembed env var can redirect it — the explicit arg wins. So the default itself has to honor HERMES_HOME.

Fix

Default the cache to <HERMES_HOME>/cache/fastembed, falling back to ~/.hermes/cache/fastembed when HERMES_HOME is unset.

_FASTEMBED_CACHE_DIR = os.environ.get(
    "MNEMOSYNE_FASTEMBED_CACHE_DIR",
    os.path.join(
        os.environ.get("HERMES_HOME", os.path.expanduser("~/.hermes")),
        "cache",
        "fastembed",
    ),
)

This matches the HERMES_HOME handling already used elsewhere in the package (mcp_tools.py), and is a no-op for anyone on the default layout (HERMES_HOME unset → identical ~/.hermes path). The explicit MNEMOSYNE_FASTEMBED_CACHE_DIR override still takes precedence.

Testing

  • ast.parse clean.
  • Verified locally on a relocated HERMES_HOME=~/.config/hermes: _FASTEMBED_CACHE_DIR resolves to ~/.config/hermes/cache/fastembed, the model loads from there, and embed() returns a (1, 384) vector. No ~/.hermes directory is recreated.

@AxDSan AxDSan left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, was IRL busy the last few days.

Nice catch. The default ~/.hermes/cache/fastembed path was the only place I leaked Hermes state outside $HERMES_HOME for users on a non-default layout. Confirmed the fix matches the HERMES_HOME pattern used in mcp_tools.py, beam.py, banks.py, memory.py, and memory_browser.py, so this is a consistency fix, not a behavior change for the default install.

Verified locally on pr/366:

  • python3 -m py_compile mnemosyne/core/embeddings.py clean.
  • With HERMES_HOME unset: _FASTEMBED_CACHE_DIR resolves to /root/.hermes/cache/fastembed (same as main).
  • With HERMES_HOME=/tmp/hermes-test: resolves to /tmp/hermes-test/cache/fastembed.
  • pytest tests/test_optional_embeddings.py tests/test_embedding_optout.py tests/test_embeddings_multilingual.py -> 24 passed in 2.71s.
  • CI green: 6/6 jobs SUCCESS (build, docs-check, test on 3.10/3.11/3.12/3.13).

Two small asks before merge:

  1. CHANGELOG entry under [Unreleased] for the fix. Even one line ("respect HERMES_HOME for fastembed cache default") keeps the release notes honest.
  2. No version bump. That is fine for this, since it is a no-op for default layouts and a correctness fix for non-default ones. Just noting I am not asking for a bump here.

Diff is small, scoped, and the comment block at the top of the change is actually useful. Approving.

mxfng added 2 commits June 22, 2026 20:24
The MNEMOSYNE_FASTEMBED_CACHE_DIR override already lets CI redirect the
fastembed model cache, but its default still hardcodes ~/.hermes and
ignores HERMES_HOME. Users who relocate HERMES_HOME (e.g. to
~/.config/hermes) get a stray ~/.hermes/cache/fastembed directory holding
~64MB of model weights, separate from the rest of their Hermes state.

Default the cache to <HERMES_HOME>/cache/fastembed, falling back to
~/.hermes when HERMES_HOME is unset. This matches the HERMES_HOME handling
already used elsewhere in the package (mcp_tools.py) and changes nothing
for users on the default layout.
@mxfng mxfng force-pushed the fix/fastembed-cache-respect-hermes-home branch from 76f15fa to a789810 Compare June 23, 2026 03:26
@mxfng

mxfng commented Jun 23, 2026

Copy link
Copy Markdown
Author

Added the CHANGELOG entry under [Unreleased] (no version bump, per your note). Also rebased onto main to pick up v3.10.1; resolved a CHANGELOG conflict from the new [3.10.1] section. Ready to merge. Thanks for the review!

@mxfng mxfng requested a review from AxDSan June 24, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants