Skip to content

feat(mem0): self-hosted dashboard backend + recall tuning (salvage #55614) - #56943

Merged
kshitijk4poor merged 3 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/55614-mem0-self-hosted
Jul 7, 2026
Merged

feat(mem0): self-hosted dashboard backend + recall tuning (salvage #55614)#56943
kshitijk4poor merged 3 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/55614-mem0-self-hosted

Conversation

@kshitijk4poor

@kshitijk4poor kshitijk4poor commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

The mem0 plugin can now connect to a self-hosted Mem0 dashboard server (the Dockerized FastAPI server), closing the gap between OSS (in-process SDK) and Platform (cloud) modes.

Changes

  • _backend.py: new SelfHostedBackend — direct httpx client for a self-hosted Mem0 server (X-API-Key auth, POST /search, GET/POST /memories, PUT/DELETE /memories/{id}), reusing the shared _unwrap_results. get_all reports the true stored total, not the page size (SelfHostedBackend.get_all() returns incorrect count when memories exceed server page limit #52921).
  • __init__.py: route to SelfHostedBackend when host is set (MEM0_HOST / mem0.json); precedence is oss > host > platform. Config schema + is_available() accept host-only (AUTH_DISABLED servers).
  • Recall tuning (mem0 research-team feedback, applies to all modes): rerank defaults to false (opt-in via rerank=true, platform only); the mem0_list tool is removed (5→4 tools); search guidance is de-shouted.
  • plugin.yaml: 1.2.01.3.0; mem0ai>=2.0.10,<3.

Maintainer follow-ups on top of the salvage

Two sibling surfaces didn't mirror the new oss > host > platform routing precedence added to _create_backend:

  • system_prompt_block() checked host before oss, so an oss+host config ran OSS but told the model it was self-hosted HTTP. Reordered to match routing.
  • hermes memory setup mem0 --mode platform left a stale host in mem0.json; since host beats platform, the user kept routing to the self-hosted server. save_config merges (no key deletion), so host is now cleared to "" (overwrites on merge, reads falsy) rather than popped.
  • Added regression tests for both; fixed a garbled Authorization: *** docstring artifact.

Validation

Result
mem0 backend + v3 + setup suites 111 passed
New guard tests (prompt-label precedence, platform host-clear) mutation-checked load-bearing
ruff / py_compile clean
Core files touched none (plugin dir + tests + docs only)

Salvage of #55614 by @kartik-mem0 (mem0 maintainer) — cherry-picked to preserve authorship, with the sibling-surface follow-ups above. Also supersedes the self-hosted portion of #52487 by @liuhao1024 (first-submitted independent implementation of the same SelfHostedBackend) — credited.

Closes #52478
Fixes #52921

Post-review follow-up (2c gates, July 8)

  • Dead code pruned: get_all() removed from the ABC + all 3 backends — mem0_list (its only caller) was removed by the recall-tuning commit, leaving new-but-unreachable code.
  • rerank config wired: the persisted mem0.json key was write-only; initialize() now parses it as the mem0_search default (per-call args win). Guard test added.
  • MEM0_HOST env-override warning on --mode platform setup — the json host-clear can't neutralize an env-var host.
  • SelfHostedBackend hardening: connect-level retries (HTTPTransport(retries=2)), injectable transport (test helper now exercises the real __init__).
  • Rebased onto current main. Suites: 443 passed / 0 failed; live E2E against a real local HTTP server: 28/28 (X-API-Key sent, AUTH_DISABLED no-header path, true-total handling, oss>host precedence proven).

@alt-glitch alt-glitch added type/feature New feature or request comp/plugins Plugin system and bundled plugins tool/memory Memory tool and memory providers P3 Low — cosmetic, nice to have labels Jul 2, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related: this is a salvage of #55614 (predecessor) and implements the same self-hosted-mem0 restore as the canonical open PR #52487 (both fix #52478 — self-hosted/host support dropped by the mem0 _backend.py v3 refactor). Not a duplicate — this salvage folds in maintainer follow-ups (routing-precedence prompt-label fix, platform-mode host-clear). Cluster for a maintainer to pick one canonical: #56943 (this salvage) / #55614 / #52487.

kartik-mem0 and others added 3 commits July 8, 2026 01:24
…usResearch#55614)

Salvage of NousResearch#55614 by @kartik-mem0 (mem0 maintainer). Adds a SelfHostedBackend
that talks to a self-hosted Mem0 Docker server over httpx (X-API-Key auth,
/search + /memories routes), gated behind `host`. Also folds in the mem0
research-team recall tuning that rides with it: rerank defaults to false across
all modes, the mem0_list tool is removed (5->4 tools), search guidance is
de-shouted, and self-hosted get_all reports the true stored total (NousResearch#52921).

Supersedes the self-hosted portion of NousResearch#52487 (@liuhao1024, first-submitted).

Closes NousResearch#52478
Fixes NousResearch#52921
…edence

Follow-up on the salvaged NousResearch#55614. The PR added host-based routing to
_create_backend (precedence: oss > host > platform) but two sibling surfaces
didn't mirror it:

- system_prompt_block() checked host before oss, so an oss+host config ran
  OSS but told the model it was self-hosted HTTP. Reordered to match routing.
- Platform setup (hermes memory setup mem0 --mode platform) left a stale host
  in mem0.json; since host beats platform, the user kept routing to the
  self-hosted server. save_config merges (no delete), so clear host to ""
  rather than pop() so the merge actually overwrites it.

Adds regression tests for both (mutation-checked).
…M0_HOST env override

Review follow-ups on the salvage:

- get_all() pruned from the ABC and all three backends: mem0_list (its
  only caller) was removed by the recall-tuning commit, leaving new,
  tested, unreachable code — including SelfHostedBackend's _MAX_TOP_K
  over-fetch workaround. Tests for it dropped; fake-class stubs remain
  harmlessly. (The NousResearch#52921 true-total fix lives on in the PR history if
  a lister ever returns.)
- The persisted rerank config key was write-only (setup prompted for it,
  nothing read it). initialize() now parses it into _rerank_default and
  mem0_search uses it when the model doesn't pass rerank explicitly;
  per-call args still win. Guard test added.
- Platform-mode setup now warns when MEM0_HOST is set in the environment:
  the json host-clear can't help there (_load_config seeds host from the
  env var, docs tell users to put it in .env) — the user would silently
  keep routing to the self-hosted server.
- SelfHostedBackend: connect-level retries (httpx.HTTPTransport(retries=2))
  so a single transient blip doesn't count toward the provider breaker;
  transport now injectable and the test helper uses the real __init__
  instead of mirroring it via __new__.
- plugin.yaml description no longer leads with reranking (off by default,
  platform-only); docs em-dash typo fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have tool/memory Memory tool and memory providers type/feature New feature or request

Projects

None yet

3 participants