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.

Studio: prefer llama-server for EmbeddingGemma in the embedding model picker (#13006)

oobaboogad632c82b7374
diff --git a/studio/backend/core/rag/embeddings.py b/studio/backend/core/rag/embeddings.py
index a1f6aa78eb5..9f3a975eb31 100644
--- a/studio/backend/core/rag/embeddings.py
+++ b/studio/backend/core/rag/embeddings.py
@@ -858,6 +858,29 @@ def _model_names_gguf_repo(model: str | None) -> bool:
return config._names_gguf(model.strip().rstrip("/").rsplit("/", 1)[-1])
+# ST under auto stays on the CPU in float32 (_device); llama-server offloads. Exact ids: a fine-tune may lack the -GGUF.
+_LLAMA_SERVER_PREFERRED_MODELS = frozenset(
+ {"unsloth/embeddinggemma-300m", "unsloth/embeddinggemma-2"}
+)
+
+
+def _plan_prefers_llama_server(model: str) -> bool:
+ """Picker plan only: the runtime follows the saved record, so an env-configured model keeps its embedding space."""
+ if model.strip().rstrip("/").lower() not in _LLAMA_SERVER_PREFERRED_MODELS:
+ return False
+ # The runtime serves the unrecorded model in effect on the hardware default; another plan would be a dead download.
+ if model == config.effective_embedding_model():
+ return False
+ # A pinned GGUF repo serves other weights; an explicit device already chose where torch runs.
+ if config.gguf_repo_is_explicit() or config.embed_device_preference() != "auto":
+ return False
+ try:
+ from utils.embedding_model_settings import get_stored_backend
+ return not get_stored_backend(model)
+ except Exception: # noqa: BLE001 - store unavailable: keep the hardware plan
+ return False
+
+
def _resolve_auto_for_model(model_name: str | None = None) -> str:
"""``auto``, but honouring the backend recorded for the saved model.
@@ -1009,12 +1032,14 @@ def resolved_backend_for_model(model_name: str, token: str | bool | None = None)
key = forced or (_resolve_auto_for_model(model_name) if raw in _AUTO_ALIASES else raw)
# Without a llama binary ST is the only plan; its error beats a fabricated GGUF destination. Stat before Hub.
if key in _ST_ALIASES and _llama_server_runtime_available():
- st_unusable = not sentence_transformers_runtime_available() or (
+ use_llama = (
+ # Auto only: an explicit ST policy ignores both the preference and the stored backend.
+ (raw in _AUTO_ALIASES and _plan_prefers_llama_server(model_name))
+ or not sentence_transformers_runtime_available()
# An ST plan for it never loads, and its pending marker blocks the llama fallback's GGUF.
- # Auto only: an explicit ST policy ignores the stored backend.
- raw in _AUTO_ALIASES and not sentence_transformers_can_load(model_name, token)
+ or (raw in _AUTO_ALIASES and not sentence_transformers_can_load(model_name, token))
)
- if st_unusable:
+ if use_llama:
key = "llama-server"
if key in _LLAMA_ALIASES:
return "llama-server"
diff --git a/studio/backend/tests/test_rag_embeddings.py b/studio/backend/tests/test_rag_embeddings.py
index cb122b580c8..bd8a44b160c 100644
--- a/studio/backend/tests/test_rag_embeddings.py
+++ b/studio/backend/tests/test_rag_embeddings.py
@@ -262,6 +262,53 @@ def test_a_replaced_backend_asks_the_hardware_again(monkeypatch):
assert asked == ["probe", "probe"]
+def test_picker_plans_embeddinggemma_on_llama_server(monkeypatch):
+ stored = {"backend": None}
+ _resolve_auto_for(monkeypatch, stored = stored)
+ monkeypatch.setattr(embeddings, "_forced_backends", {})
+ monkeypatch.setattr(config, "EMBED_DEVICE", "auto")
+ monkeypatch.delenv("RAG_EMBED_GGUF_REPO", raising = False)
+ monkeypatch.setattr(embeddings, "sentence_transformers_runtime_available", lambda: True)
+ monkeypatch.setattr(embeddings, "_llama_server_runtime_available", lambda: True)
+ monkeypatch.setattr(embeddings, "sentence_transformers_can_load", lambda *a, **k: True)
+ effective = {"model": "org/previous-embedder"}
+ monkeypatch.setattr(config, "effective_embedding_model", lambda: effective["model"])
+ plan = embeddings.resolved_backend_for_model
+
+ assert plan("unsloth/embeddinggemma-300m") == "llama-server"
+ assert plan("unsloth/embeddinggemma-2") == "llama-server"
+ # Exact ids: a fine-tune need not publish the GGUF the preference relies on.
+ assert plan("org/embeddinggemma-300m-finetune") == "sentence-transformers"
+ # Only the plan: the runtime follows the saved record, so an env-configured model keeps its space.
+ assert embeddings._resolve_auto_for_model("unsloth/embeddinggemma-300m") == (
+ "sentence-transformers"
+ )
+ # The model in effect without a record runs on that default, and its Settings status must say so.
+ effective["model"] = "unsloth/embeddinggemma-300m"
+ assert plan("unsloth/embeddinggemma-300m") == "sentence-transformers"
+ effective["model"] = "org/previous-embedder"
+
+ # A model saved on sentence-transformers keeps the space its documents were indexed in.
+ stored["backend"] = "sentence-transformers"
+ assert plan("unsloth/embeddinggemma-300m") == "sentence-transformers"
+ stored["backend"] = None
+
+ monkeypatch.setattr(config, "EMBED_DEVICE", "gpu")
+ assert plan("unsloth/embeddinggemma-300m") == "sentence-transformers"
+ monkeypatch.setattr(config, "EMBED_DEVICE", "auto")
+
+ monkeypatch.setenv("RAG_EMBED_GGUF_REPO", "org/other-GGUF")
+ assert plan("unsloth/embeddinggemma-300m") == "sentence-transformers"
+ monkeypatch.delenv("RAG_EMBED_GGUF_REPO")
+
+ monkeypatch.setattr(config, "EMBED_BACKEND", "sentence-transformers")
+ assert plan("unsloth/embeddinggemma-300m") == "sentence-transformers"
+ monkeypatch.setattr(config, "EMBED_BACKEND", "auto")
+
+ monkeypatch.setattr(embeddings, "_llama_server_runtime_available", lambda: False)
+ assert plan("unsloth/embeddinggemma-300m") == "sentence-transformers"
+
+
def test_a_resolution_that_never_asked_the_hardware_keeps_nothing(monkeypatch):
"""``_get_backend`` clears the per-thread answer before resolving, and that clear is
load-bearing: the identity and active-backend probes also resolve ``auto`` outside the