Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Point unsloth start openclaw memory search at the Unsloth embeddings API (#10320)

Nilay083113bf24d5
diff --git a/unsloth_cli/commands/start.py b/unsloth_cli/commands/start.py
index 713bf2635ef..148ae91f2e5 100644
--- a/unsloth_cli/commands/start.py
+++ b/unsloth_cli/commands/start.py
@@ -4645,6 +4645,26 @@ def _session_config(
yield path
+def _studio_embedding_model(base: str, key: str) -> Optional[str]:
+ """Studio's configured embedding model, or None when this server cannot say.
+
+ Not a model name: a name this server will not serve, beside fallback "none", is the one
+ combination OpenClaw cannot degrade out of. The caller writes provider "none" instead.
+ """
+ try:
+ info = _http_json("GET", f"{base}/api/settings/embedding-model", key, timeout = 10)
+ # typer.Exit is a RuntimeError subclass: the broad catch would swallow a deliberate abort.
+ except (typer.Exit, typer.Abort, click.exceptions.Exit, click.exceptions.Abort):
+ raise
+ except Exception: # noqa: BLE001 - an older or unreachable server still gets a working config
+ return None
+ name = info.get("embedding_model") if isinstance(info, dict) else None
+ if not isinstance(name, str) or not name.strip():
+ return None
+ # OpenClaw sends this to /v1/embeddings verbatim; Settings stores what was typed.
+ return name.strip()
+
+
def write_openclaw_config(
base: str,
key: str,
@@ -4652,6 +4672,7 @@ def write_openclaw_config(
path: Path,
yolo: bool = False,
workspace_path: Optional[str] = None,
+ embedding_model: Optional[str] = None,
) -> None:
config = _read_json_object(path)
if config is None:
@@ -4675,6 +4696,24 @@ def write_openclaw_config(
"api": "openai-completions",
"models": [provider_model],
}
+ # Memory search is on by default and defaults to openai, so a local session reaches
+ # OpenAI unless this block is written.
+ search = _subdict(_subdict(config, "memory"), "search")
+ if embedding_model:
+ search.update(
+ {
+ "provider": "openai-compatible",
+ "model": embedding_model,
+ "fallback": "none",
+ "remote": {"baseUrl": f"{base}/v1", "apiKey": key},
+ }
+ )
+ else:
+ # "none" is OpenClaw's keyword-only mode: no network call, and search still returns
+ # hits. Clearing the remote stops a reused --persist config aiming at a dead endpoint.
+ search.update({"provider": "none", "fallback": "none"})
+ search.pop("model", None)
+ search.pop("remote", None)
# Pin a default model, else OpenClaw drops into its setup agent ("no models available").
agents = _subdict(config, "agents")
defaults = _subdict(agents, "defaults")
@@ -5364,6 +5403,7 @@ def openclaw(
config_path,
yolo = yolo,
workspace_path = "${OPENCLAW_WORKSPACE_DIR}",
+ embedding_model = _studio_embedding_model(base, key),
)
# Scope both config and state so OpenClaw never touches the user's ~/.openclaw.
env = {"OPENCLAW_CONFIG_PATH": str(config_path), "OPENCLAW_STATE_DIR": str(cfg)}
diff --git a/unsloth_cli/tests/test_start.py b/unsloth_cli/tests/test_start.py
index 321036c933f..13ab52fa7a7 100644
--- a/unsloth_cli/tests/test_start.py
+++ b/unsloth_cli/tests/test_start.py
@@ -1510,6 +1510,8 @@ def fake_studio(tmp_path, monkeypatch):
return {"is_gguf": True, "model_identifier": state["models"][0]["id"]}
if url.endswith("/api/auth/api-keys"):
return {"key": "sk-unsloth-feedfacefeedface"}
+ if url.endswith("/api/settings/embedding-model"):
+ return {"embedding_model": "unsloth/bge-small-en-v1.5"}
if url.endswith("/api/inference/load"):
already_loaded = state["models"][0]["id"] == payload["model_path"]
state["models"] = [{"id": payload["model_path"], "context_length": 4096}]
@@ -4711,6 +4713,12 @@ def test_connect_openclaw_no_launch(fake_studio, tmp_path, monkeypatch):
assert config["agents"]["defaults"]["model"]["primary"] == f"unsloth/{MODEL['id']}"
assert config["agents"]["defaults"]["skipBootstrap"] is True
assert config["agents"]["defaults"]["workspace"] == "${OPENCLAW_WORKSPACE_DIR}"
+ assert config["memory"]["search"] == {
+ "provider": "openai-compatible",
+ "model": "unsloth/bge-small-en-v1.5",
+ "fallback": "none",
+ "remote": {"baseUrl": f"{BASE}/v1", "apiKey": "sk-unsloth-feedfacefeedface"},
+ }
_assert_env_cwd(result.output, "OPENCLAW_WORKSPACE_DIR")
assert _launch_command(result.output) == ["openclaw", "tui", "--local"]
# OpenAI /v1/chat/completions works on either backend — no GGUF gate.
@@ -8731,3 +8739,98 @@ def test_a_status_body_without_is_gguf_still_launches(fake_studio, monkeypatch,
result = CliRunner().invoke(start.start_app, [agent, "--no-launch"])
assert result.exit_code == 0, result.output
assert "needs a GGUF model" not in result.output
+
+
+def _openclaw_without_the_settings_route(monkeypatch, exc = RuntimeError("404")):
+ real = start._http_json
+
+ def older_server(method, url, *args, **kwargs):
+ if url.endswith("/api/settings/embedding-model"):
+ raise exc
+ return real(method, url, *args, **kwargs)
+
+ monkeypatch.setattr(start, "_http_json", older_server)
+
+
+def test_openclaw_memory_search_asks_for_keyword_only_without_the_settings_route(
+ fake_studio, tmp_path, monkeypatch
+):
+ # A server that cannot name its embedder will not serve it either, and that name
+ # beside fallback "none" is the one shape OpenClaw cannot degrade out of.
+ _openclaw_without_the_settings_route(monkeypatch)
+ monkeypatch.chdir(tmp_path)
+ result = CliRunner().invoke(start.start_app, ["openclaw", "--no-launch"])
+ assert result.exit_code == 0, result.output
+ config = json.loads((tmp_path / "agents" / "openclaw" / "openclaw.json").read_text())
+ search = config["memory"]["search"]
+ assert search == {"provider": "none", "fallback": "none"}
+
+
+def test_openclaw_memory_search_drops_a_stale_remote_when_the_route_is_gone(
+ fake_studio, tmp_path, monkeypatch
+):
+ # A --persist config must not keep the old endpoint and key for a dropped provider.
+ _openclaw_without_the_settings_route(monkeypatch)
+ monkeypatch.chdir(tmp_path)
+ config_path = tmp_path / "agents" / "openclaw" / "openclaw.json"
+ config_path.parent.mkdir(parents = True)
+ config_path.write_text(
+ json.dumps(
+ {
+ "memory": {
+ "search": {
+ "provider": "openai-compatible",
+ "model": "unsloth/bge-small-en-v1.5",
+ "fallback": "none",
+ "remote": {
+ "baseUrl": "http://127.0.0.1:8888/v1",
+ "apiKey": "sk-unsloth-old",
+ },
+ }
+ }
+ }
+ )
+ )
+ result = CliRunner().invoke(start.start_app, ["openclaw", "--no-launch"])
+ assert result.exit_code == 0, result.output
+ search = json.loads(config_path.read_text())["memory"]["search"]
+ assert search == {"provider": "none", "fallback": "none"}
+
+
+def test_openclaw_memory_search_model_is_stripped(fake_studio, tmp_path, monkeypatch):
+ # The model goes to /v1/embeddings verbatim, so padding would reach the request.
+ real = start._http_json
+
+ def padded(method, url, *args, **kwargs):
+ if url.endswith("/api/settings/embedding-model"):
+ return {"embedding_model": " unsloth/bge-small-en-v1.5\n"}
+ return real(method, url, *args, **kwargs)
+
+ monkeypatch.setattr(start, "_http_json", padded)
+ monkeypatch.chdir(tmp_path)
+ result = CliRunner().invoke(start.start_app, ["openclaw", "--no-launch"])
+ assert result.exit_code == 0, result.output
+ config = json.loads((tmp_path / "agents" / "openclaw" / "openclaw.json").read_text())
+ assert config["memory"]["search"]["model"] == "unsloth/bge-small-en-v1.5"
+
+
+def test_openclaw_memory_search_does_not_swallow_a_cli_abort(fake_studio, tmp_path, monkeypatch):
+ # typer.Exit is a RuntimeError subclass: a bare except would degrade the config silently.
+ _openclaw_without_the_settings_route(monkeypatch, exc = typer.Exit(2))
+ monkeypatch.chdir(tmp_path)
+ result = CliRunner().invoke(start.start_app, ["openclaw", "--no-launch"])
+ assert result.exit_code == 2, result.output
+
+
+def test_openclaw_memory_search_clears_a_stale_external_fallback(
+ fake_studio, tmp_path, monkeypatch
+):
+ monkeypatch.chdir(tmp_path)
+ config_path = tmp_path / "agents" / "openclaw" / "openclaw.json"
+ config_path.parent.mkdir(parents = True)
+ config_path.write_text(json.dumps({"memory": {"search": {"fallback": "openai"}}}))
+ result = CliRunner().invoke(start.start_app, ["openclaw", "--no-launch"])
+ assert result.exit_code == 0, result.output
+ config = json.loads(config_path.read_text())
+ assert config["memory"]["search"]["fallback"] == "none"
+ assert config["memory"]["search"]["provider"] == "openai-compatible"