feat(memory): make the mem0 sync char cap configurable via mem0.json

A flat 450-char cap fits 512-token embedders (bge-small-zh-v1.5,
all-minilm) but stores only ~5% of the window on 8192-token models
(text-embedding-3-small, jina-embeddings-v3, bge-m3), degrading memory
quality for users those models served fine before truncation existed.

Read `sync_max_chars` from mem0.json once in initialize() (450 default)
and pass it to _truncate_for_sync(). Config over auto-detection: the
Ollama /api/show probe + known-model table proposed in #37427 adds a
network call and a curated list for a number the operator already knows
from their embedder choice; the setup wizard's mem0.json is the plugin's
behavioral-settings surface (no new HERMES_* env var). Documented in the
plugin README and the memory-providers docs page.

Dynamic-cap requirement and measurements (450 OK / 600 -> HTTP 500 on
bge-small-zh-v1.5:f16) by @szicely in #106235.

Refs #37421 #106235
Co-authored-by: szicely <140148567+szicely@users.noreply.github.com>
Co-authored-by: liuhao1024 <sunsky.lau@gmail.com>
This commit is contained in:
teknium1
2026-09-09 04:53:12 -07:00
committed by Teknium
parent 040742d06b
commit 322905e91b
4 changed files with 19 additions and 2 deletions
+11
View File
@@ -180,6 +180,17 @@ class TestSyncTurnTruncation:
assert len(sent[1]["content"]) <= mem0_plugin._SYNC_MSG_MAX_CHARS and sent[1]["content"].endswith(".")
assert provider._consecutive_failures == 0
def test_sync_max_chars_config_raises_cap(self, monkeypatch, tmp_path):
"""8k-token embedders should not be stuck at the 512-token default (#106235)."""
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
monkeypatch.setenv("MEM0_API_KEY", "test-key")
(tmp_path / "mem0.json").write_text('{"sync_max_chars": 3000}')
backend = FakeBackend()
provider = self._make_provider(monkeypatch, backend)
provider.sync_turn("hi", "Long answer. " * 200, session_id="s1") # 2600 chars
provider._sync_thread.join(timeout=2)
assert backend.captured[0][1][1]["content"] == "Long answer. " * 200
class TestMem0Prefetch:
"""prefetch() must recall on the CURRENT question, synchronously.