Skip to content
Python

fix(memhub): the embedding endpoint no longer follows the generation base_url

alvinfei2ab04291a990
diff --git a/memhub/apps/core/src/one_memory/api.py b/memhub/apps/core/src/one_memory/api.py
index da2b7d9..419814f 100644
--- a/memhub/apps/core/src/one_memory/api.py
+++ b/memhub/apps/core/src/one_memory/api.py
@@ -189,6 +189,7 @@ from one_memory.model_presets import seed_preset_profile
from one_memory.model_probe import ModelProber, ModelProbeResult
from one_memory.model_profiles import (
ActiveModelProfileError,
+ EmbeddingBaseUrlRequiredError,
ModelCreationOperationConflictError,
ModelCreationOperationLookupError,
ModelCreationOperationReceipt,
@@ -2873,6 +2874,8 @@ def create_app(
def create_model_profile(request: ModelProfileInput) -> ModelProfile:
try:
return _model_profile_store(app).create(request, _secret_store(app))
+ except EmbeddingBaseUrlRequiredError:
+ raise HTTPException(422, "embedding_base_url_required") from None
except ModelCreationOperationConflictError:
raise HTTPException(409, "model_creation_operation_conflict") from None
except ModelCreationOperationLookupError:
@@ -2924,6 +2927,8 @@ def create_app(
raise HTTPException(status_code=404, detail="model_profile_not_found") from None
except ModelProfileConflictError:
raise HTTPException(status_code=409, detail="model_profile_conflict") from None
+ except EmbeddingBaseUrlRequiredError:
+ raise HTTPException(status_code=422, detail="embedding_base_url_required") from None
except SecretStoreUnavailableError as error:
raise HTTPException(
status_code=503,
diff --git a/memhub/apps/core/src/one_memory/hy_sdk_runtime.py b/memhub/apps/core/src/one_memory/hy_sdk_runtime.py
index 0acedcf..c52a740 100644
--- a/memhub/apps/core/src/one_memory/hy_sdk_runtime.py
+++ b/memhub/apps/core/src/one_memory/hy_sdk_runtime.py
@@ -228,7 +228,7 @@ def retrieval_view(profile: ModelProfileSnapshot) -> ModelProfileSnapshot:
provider = profile.embedding_provider_kind or profile.provider_kind
endpoint: str | None = None
if provider is not ProviderKind.LOCAL_ONNX:
- endpoint = profile.embedding_base_url or profile.base_url
+ endpoint = profile.embedding_base_url
if not endpoint:
raise HySdkRuntimeError("hy_sdk_model_endpoint_missing")
return builtin_retrieval_snapshot().model_copy(
@@ -276,10 +276,8 @@ def build_sdk_config(
embedding_key = None
dimensions = profile.embedding_dimensions or BUILTIN_EMBEDDING_DIMENSIONS
else:
- embedding_endpoint = _openai_endpoint(
- embedding_provider,
- profile.embedding_base_url or profile.base_url,
- )
+ # Never the generation endpoint: the collection name hashes this one.
+ embedding_endpoint = _openai_endpoint(embedding_provider, profile.embedding_base_url)
embedding_key = "ollama" if embedding_provider is ProviderKind.OLLAMA else api_key
if embedding_provider is ProviderKind.OPENAI_COMPATIBLE and not embedding_key:
raise HySdkRuntimeError("hy_sdk_embedding_api_key_missing")
@@ -494,7 +492,7 @@ def vector_collection_bases(profile: ModelProfileSnapshot) -> tuple[str, tuple[s
endpoint, dimensions = None, profile.embedding_dimensions or BUILTIN_EMBEDDING_DIMENSIONS
legacy_endpoint = "local-onnx"
else:
- endpoint = _openai_endpoint(provider, profile.embedding_base_url or profile.base_url)
+ endpoint = _openai_endpoint(provider, profile.embedding_base_url)
dimensions = profile.embedding_dimensions
legacy_endpoint = endpoint
legacy_model = profile.embedding_model or "bge-small-zh-v1.5"
diff --git a/memhub/apps/core/src/one_memory/model_probe.py b/memhub/apps/core/src/one_memory/model_probe.py
index b12d418..3b86b1e 100644
--- a/memhub/apps/core/src/one_memory/model_probe.py
+++ b/memhub/apps/core/src/one_memory/model_probe.py
@@ -564,7 +564,7 @@ def _embedding_request(
secret: str | None,
) -> tuple[str, str, dict[str, str], dict[str, object]]:
provider = profile.embedding_provider_kind or profile.provider_kind
- base_url = (profile.embedding_base_url or profile.base_url or "").rstrip("/")
+ base_url = (profile.embedding_base_url or "").rstrip("/")
if provider is ProviderKind.OLLAMA:
return (
"POST",
diff --git a/memhub/apps/core/src/one_memory/model_profiles.py b/memhub/apps/core/src/one_memory/model_profiles.py
index ce8e863..17cc75e 100644
--- a/memhub/apps/core/src/one_memory/model_profiles.py
+++ b/memhub/apps/core/src/one_memory/model_profiles.py
@@ -97,7 +97,6 @@ class ModelProfileInput(BaseModel):
)
embedding_provider, resolved_embedding_base_url = resolve_embedding_endpoint(
provider_kind=self.provider_kind,
- base_url=base_url,
embedding_model=embedding_model,
embedding_provider_kind=embedding_provider_kind,
embedding_base_url=embedding_base_url,
@@ -107,6 +106,12 @@ class ModelProfileInput(BaseModel):
ProviderKind.ANTHROPIC,
}:
raise ValueError("embedding provider must be OpenAI-compatible, Ollama, or local ONNX")
+ if (
+ embedding_provider is not ProviderKind.LOCAL_ONNX
+ and resolved_embedding_base_url is None
+ ):
+ # `ModelProfileStore.create` refuses it with its own code.
+ return self
if (
embedding_provider is not ProviderKind.LOCAL_ONNX
and resolved_embedding_base_url is not None
@@ -308,11 +313,12 @@ class ModelProfileStore:
f"""
UPDATE {table}
SET embedding_provider_kind = provider_kind,
- embedding_base_url = base_url
+ embedding_base_url = COALESCE(embedding_base_url, base_url)
WHERE embedding_model IS NOT NULL
AND embedding_provider_kind IS NULL
"""
)
+ _pin_embedding_endpoints(connection, table)
connection.execute(
"""
INSERT OR IGNORE INTO model_profile_versions (
@@ -355,11 +361,11 @@ class ModelProfileStore:
)
embedding_provider_kind, embedding_base_url = resolve_embedding_endpoint(
provider_kind=value.provider_kind,
- base_url=base_url,
embedding_model=defaulted_model,
embedding_provider_kind=defaulted_provider,
embedding_base_url=defaulted_base_url,
)
+ require_embedding_base_url(embedding_provider_kind, embedding_base_url)
try:
with self._connect(writing=True) as connection:
connection.execute(
@@ -612,7 +618,6 @@ class ModelProfileStore:
)
embedding_provider_kind, embedding_base_url = resolve_embedding_endpoint(
provider_kind=current.provider_kind,
- base_url=base_url,
embedding_model=embedding_model,
embedding_provider_kind=(
patch.embedding_provider_kind
@@ -627,6 +632,7 @@ class ModelProfileStore:
)
if embedding_provider_kind in {ProviderKind.HY_DEFAULT, ProviderKind.ANTHROPIC}:
raise ValueError("embedding provider must be OpenAI-compatible, Ollama, or local ONNX")
+ require_embedding_base_url(embedding_provider_kind, embedding_base_url)
if (
embedding_provider_kind is not ProviderKind.LOCAL_ONNX
and embedding_base_url is not None
@@ -1167,21 +1173,77 @@ def attach_disable_thinking(
def resolve_embedding_endpoint(
*,
provider_kind: ProviderKind,
- base_url: str | None,
embedding_model: str | None,
embedding_provider_kind: ProviderKind | None,
embedding_base_url: str | None,
) -> tuple[ProviderKind | None, str | None]:
+ """The embedding provider and the endpoint exactly as given.
+
+ The endpoint never follows the generation `base_url`: the collection name
+ hashes it, so a proxy or region edit of the generation endpoint moved
+ writes to a new, empty collection, and providers without embeddings were
+ sent embedding requests. `require_embedding_base_url` refuses a remote
+ embedding without one.
+ """
if embedding_model is None:
return None, None
if embedding_provider_kind is ProviderKind.LOCAL_ONNX:
return ProviderKind.LOCAL_ONNX, None
- if embedding_provider_kind is None:
- return provider_kind, embedding_base_url or base_url
- return (
- embedding_provider_kind,
- embedding_base_url or DEFAULT_BASE_URLS.get(embedding_provider_kind),
- )
+ return embedding_provider_kind or provider_kind, embedding_base_url
+
+
+class EmbeddingBaseUrlRequiredError(ValueError):
+ def __init__(self) -> None:
+ super().__init__("embedding_base_url_required")
+
+
+def require_embedding_base_url(provider: ProviderKind | None, base_url: str | None) -> None:
+ """A remote embedding must name its endpoint; the UI may offer the generation one."""
+ if provider not in {None, ProviderKind.LOCAL_ONNX} and not base_url:
+ raise EmbeddingBaseUrlRequiredError()
+
+
+def pinned_embedding_base_url(
+ *,
+ provider_kind: ProviderKind | str,
+ base_url: str | None,
+ embedding_model: str | None,
+ embedding_provider_kind: ProviderKind | str | None,
+ embedding_base_url: str | None,
+) -> str | None:
+ """The endpoint a stored profile's embedding resolved to before it was pinned.
+
+ The Runtime used `embedding_base_url or base_url`, and the provider default
+ only when both were empty (no collection could have existed then). Writing
+ that value keeps the endpoint, and so the collection name, byte-identical.
+ """
+ provider = ProviderKind(embedding_provider_kind or provider_kind)
+ if embedding_model is None or embedding_base_url or provider is ProviderKind.LOCAL_ONNX:
+ return embedding_base_url
+ return base_url or DEFAULT_BASE_URLS.get(provider)
+
+
+def _pin_embedding_endpoints(connection: sqlite3.Connection, table: str) -> None:
+ """Write the resolved endpoint into every remote embedding left without one."""
+ rows = connection.execute(
+ f"SELECT rowid, provider_kind, base_url, embedding_model, embedding_provider_kind "
+ f"FROM {table} WHERE embedding_model IS NOT NULL AND embedding_base_url IS NULL "
+ "AND COALESCE(embedding_provider_kind, provider_kind) != 'local_onnx'"
+ ).fetchall()
+ for row in rows:
+ connection.execute(
+ f"UPDATE {table} SET embedding_base_url = ? WHERE rowid = ?",
+ (
+ pinned_embedding_base_url(
+ provider_kind=row["provider_kind"],
+ base_url=row["base_url"],
+ embedding_model=row["embedding_model"],
+ embedding_provider_kind=row["embedding_provider_kind"],
+ embedding_base_url=None,
+ ),
+ row["rowid"],
+ ),
+ )
def validate_model_base_url(value: str) -> None:
diff --git a/memhub/apps/core/src/one_memory/sdk_migration_verify.py b/memhub/apps/core/src/one_memory/sdk_migration_verify.py
index 19fab77..a452b35 100644
--- a/memhub/apps/core/src/one_memory/sdk_migration_verify.py
+++ b/memhub/apps/core/src/one_memory/sdk_migration_verify.py
@@ -19,7 +19,7 @@ from pathlib import Path
from typing import Any
from one_memory.database_access import main_database
-from one_memory.model_profiles import ModelProfileSnapshot
+from one_memory.model_profiles import ModelProfileSnapshot, pinned_embedding_base_url
from one_memory.sdk_data_plane_migration import DataPlaneMigrationError
_PRODUCTIVITY_KINDS = frozenset({"coding", "working"})
@@ -184,7 +184,14 @@ def read_active_profile(database_path: Path) -> ModelProfileSnapshot | None:
model=row["model"],
embedding_model=row["embedding_model"],
embedding_provider_kind=row["embedding_provider_kind"],
- embedding_base_url=row["embedding_base_url"],
+ # Read-only, beside a Core that may not have pinned it yet.
+ embedding_base_url=pinned_embedding_base_url(
+ provider_kind=row["provider_kind"],
+ base_url=row["base_url"],
+ embedding_model=row["embedding_model"],
+ embedding_provider_kind=row["embedding_provider_kind"],
+ embedding_base_url=row["embedding_base_url"],
+ ),
embedding_dimensions=row["embedding_dimensions"],
timeout_seconds=row["timeout_seconds"],
max_concurrency=row["max_concurrency"],
diff --git a/memhub/apps/core/tests/graph_fixtures.py b/memhub/apps/core/tests/graph_fixtures.py
index 660922a..bd04ee7 100644
--- a/memhub/apps/core/tests/graph_fixtures.py
+++ b/memhub/apps/core/tests/graph_fixtures.py
@@ -24,7 +24,8 @@ def model_snapshot(
model="memory-model",
embedding_model="embedding-model",
embedding_provider_kind=embedding_provider,
- embedding_base_url=embedding_base_url,
+ # Stored profiles always name it; see `pinned_embedding_base_url`.
+ embedding_base_url=embedding_base_url or base_url,
embedding_dimensions=768,
timeout_seconds=30,
max_concurrency=1,
diff --git a/memhub/apps/core/tests/test_memory_batch_extraction.py b/memhub/apps/core/tests/test_memory_batch_extraction.py
index 46edd68..c7355b5 100644
--- a/memhub/apps/core/tests/test_memory_batch_extraction.py
+++ b/memhub/apps/core/tests/test_memory_batch_extraction.py
@@ -26,6 +26,7 @@ def snapshot() -> ModelProfileSnapshot:
base_url="http://127.0.0.1:11434",
model="memory-model",
embedding_model="embedding-model",
+ embedding_base_url="http://127.0.0.1:11434",
embedding_dimensions=768,
timeout_seconds=30,
max_concurrency=1,
diff --git a/memhub/apps/core/tests/test_memory_qa.py b/memhub/apps/core/tests/test_memory_qa.py
index e6b7d9b..f5d20b0 100644
--- a/memhub/apps/core/tests/test_memory_qa.py
+++ b/memhub/apps/core/tests/test_memory_qa.py
@@ -66,6 +66,7 @@ def _grounded_setup(tmp_path, *, memory_id: str = "memory-real-data"):
base_url="http://127.0.0.1:11434",
model="test-model",
embedding_model="test-embedding",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
@@ -263,6 +264,7 @@ def test_answer_uses_only_grounded_confirmed_memory_citations(tmp_path) -> None:
base_url="http://127.0.0.1:11434",
model="test-model",
embedding_model="test-embedding",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
@@ -468,6 +470,7 @@ def test_answer_rejects_model_citation_outside_retrieved_scope(tmp_path) -> None
base_url="http://127.0.0.1:11434",
model="test-model",
embedding_model="test-embedding",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
@@ -530,6 +533,7 @@ def _compatible_gateway_setup(tmp_path):
base_url="https://api.example.invalid/standard/v1",
model="deepseek-v4-pro",
embedding_model="text-embedding",
+ embedding_base_url="https://api.example.invalid/standard/v1",
api_key="probe-key",
),
secrets,
diff --git a/memhub/apps/core/tests/test_memory_qa_permissions.py b/memhub/apps/core/tests/test_memory_qa_permissions.py
index c86fccf..51b3252 100644
--- a/memhub/apps/core/tests/test_memory_qa_permissions.py
+++ b/memhub/apps/core/tests/test_memory_qa_permissions.py
@@ -186,6 +186,7 @@ def _setup(tmp_path: Path, *, model: str = "available") -> _Setup:
base_url="https://memory-qa.example.invalid/v1",
model="synthetic-generation",
embedding_model="synthetic-embedding",
+ embedding_base_url="https://memory-qa.example.invalid/v1",
api_key=SecretStr(_SECRET),
),
secrets,
diff --git a/memhub/apps/core/tests/test_memory_task_unknown_retry.py b/memhub/apps/core/tests/test_memory_task_unknown_retry.py
index 40720bf..58a32bc 100644
--- a/memhub/apps/core/tests/test_memory_task_unknown_retry.py
+++ b/memhub/apps/core/tests/test_memory_task_unknown_retry.py
@@ -25,6 +25,7 @@ def _stores(tmp_path):
provider_kind=ProviderKind.OLLAMA,
model="hy-bot-phi4",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
diff --git a/memhub/apps/core/tests/test_memory_tasks.py b/memhub/apps/core/tests/test_memory_tasks.py
index d6690bd..ef28818 100644
--- a/memhub/apps/core/tests/test_memory_tasks.py
+++ b/memhub/apps/core/tests/test_memory_tasks.py
@@ -83,6 +83,7 @@ def test_task_freezes_active_profile_revision_and_is_idempotent(tmp_path) -> Non
provider_kind=ProviderKind.OLLAMA,
model="qwen",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
@@ -240,6 +241,7 @@ def test_task_extraction_checkpoint_is_idempotent_and_recoverable(tmp_path) -> N
provider_kind=ProviderKind.OLLAMA,
model="qwen",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
),
@@ -293,6 +295,7 @@ def test_task_waits_for_model_and_retries_with_same_snapshot(tmp_path) -> None:
provider_kind=ProviderKind.OLLAMA,
model="qwen",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
@@ -337,6 +340,7 @@ def test_blocked_stages_name_the_stuck_stage_and_reason(tmp_path) -> None:
provider_kind=ProviderKind.OLLAMA,
model="qwen",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
),
@@ -433,6 +437,7 @@ def test_task_duration_estimate_ignores_time_the_app_was_closed(tmp_path) -> Non
provider_kind=ProviderKind.OLLAMA,
model="qwen",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
),
@@ -537,6 +542,7 @@ def test_running_task_is_recovered_after_worker_restart(tmp_path) -> None:
provider_kind=ProviderKind.OLLAMA,
model="qwen",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
),
@@ -572,6 +578,7 @@ def test_superseded_profile_cancels_only_claimable_tasks(tmp_path) -> None:
provider_kind=ProviderKind.OLLAMA,
model="phi",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
),
@@ -601,6 +608,7 @@ def test_superseded_profile_cancels_only_claimable_tasks(tmp_path) -> None:
provider_kind=ProviderKind.OLLAMA,
model="qwen",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
),
@@ -630,6 +638,7 @@ def test_superseded_ingest_policy_cancels_only_old_conversation_tasks(tmp_path)
provider_kind=ProviderKind.OLLAMA,
model="qwen",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
),
@@ -676,6 +685,7 @@ def test_task_rejects_inactive_profile_and_request_id_reuse(tmp_path) -> None:
provider_kind=ProviderKind.OLLAMA,
model="qwen",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
@@ -1700,6 +1710,7 @@ def _profile_and_tasks(tmp_path) -> tuple[MemoryTaskStore, ModelProfile]:
provider_kind=ProviderKind.OLLAMA,
model="qwen",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
),
@@ -2058,6 +2069,7 @@ def test_a_failed_task_below_the_ceiling_is_still_claimable(tmp_path) -> None:
provider_kind=ProviderKind.OLLAMA,
model="qwen",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
),
diff --git a/memhub/apps/core/tests/test_memory_visibility.py b/memhub/apps/core/tests/test_memory_visibility.py
index 908f9d4..82e1ccb 100644
--- a/memhub/apps/core/tests/test_memory_visibility.py
+++ b/memhub/apps/core/tests/test_memory_visibility.py
@@ -55,6 +55,7 @@ def library(tmp_path):
provider_kind=ProviderKind.OLLAMA,
model="hy-bot-phi4",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
diff --git a/memhub/apps/core/tests/test_memory_visibility_equivalence.py b/memhub/apps/core/tests/test_memory_visibility_equivalence.py
index accea34..3a2850c 100644
--- a/memhub/apps/core/tests/test_memory_visibility_equivalence.py
+++ b/memhub/apps/core/tests/test_memory_visibility_equivalence.py
@@ -51,6 +51,7 @@ def library(tmp_path):
provider_kind=ProviderKind.OLLAMA,
model="hy-bot-phi4",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
diff --git a/memhub/apps/core/tests/test_model_probe.py b/memhub/apps/core/tests/test_model_probe.py
index dafd72e..148e589 100644
--- a/memhub/apps/core/tests/test_model_probe.py
+++ b/memhub/apps/core/tests/test_model_probe.py
@@ -28,6 +28,7 @@ def test_probe_still_measures_embedding_when_structured_output_fails(tmp_path) -
base_url="http://127.0.0.1:11434",
model="plain-model",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
@@ -63,6 +64,7 @@ def test_probe_records_the_real_embedding_width_on_the_profile(tmp_path) -> None
base_url="http://127.0.0.1:11434",
model="qwen3:8b",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
@@ -119,6 +121,7 @@ def test_openai_compatible_probe_checks_model_and_structured_output(tmp_path) ->
base_url="https://models.example.com/v1",
model="memory-model",
embedding_model="embedding-model",
+ embedding_base_url="https://models.example.com/v1",
api_key=SecretStr(API_KEY),
),
secrets,
@@ -260,6 +263,7 @@ def test_probe_reports_missing_model_without_sending_generation(tmp_path) -> Non
provider_kind=ProviderKind.OLLAMA,
model="memory-model",
embedding_model="embedding-model",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
diff --git a/memhub/apps/core/tests/test_model_profile_api.py b/memhub/apps/core/tests/test_model_profile_api.py
index 72e7811..8fb6395 100644
--- a/memhub/apps/core/tests/test_model_profile_api.py
+++ b/memhub/apps/core/tests/test_model_profile_api.py
@@ -50,6 +50,7 @@ def test_model_profile_api_never_returns_key_and_enforces_revision(tmp_path) ->
"base_url": "https://models.example.com/v1",
"model": "memory-model",
"embedding_model": "embedding-model",
+ "embedding_base_url": "https://models.example.com/v1",
"api_key": API_KEY,
},
)
@@ -134,6 +135,7 @@ def test_model_profile_probe_route_returns_only_machine_results(tmp_path) -> Non
"base_url": "https://models.example.com/v1",
"model": "memory-model",
"embedding_model": "embedding-model",
+ "embedding_base_url": "https://models.example.com/v1",
"api_key": API_KEY,
},
)
@@ -244,6 +246,7 @@ def test_activation_survives_a_corpus_already_imported(tmp_path) -> None:
"base_url": "https://models.example.com/v1",
"model": "memory-model",
"embedding_model": "embedding-model",
+ "embedding_base_url": "https://models.example.com/v1",
"api_key": API_KEY,
},
)
diff --git a/memhub/apps/core/tests/test_model_profiles.py b/memhub/apps/core/tests/test_model_profiles.py
index 53ae697..7e9745d 100644
--- a/memhub/apps/core/tests/test_model_profiles.py
+++ b/memhub/apps/core/tests/test_model_profiles.py
@@ -198,6 +198,7 @@ def test_active_profile_can_be_deleted_without_changing_other_profiles(tmp_path)
provider_kind=ProviderKind.OLLAMA,
model="other",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
@@ -208,6 +209,7 @@ def test_active_profile_can_be_deleted_without_changing_other_profiles(tmp_path)
base_url="https://models.example.com/v1",
model="qwen",
embedding_model="nomic-embed-text",
+ embedding_base_url="https://models.example.com/v1",
api_key=SecretStr(API_KEY),
),
secrets,
@@ -349,6 +351,7 @@ def _probed(store, secrets, *, structured: bool, generates: bool = True):
provider_kind=ProviderKind.OLLAMA,
model="qwen",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
@@ -394,3 +397,102 @@ def test_a_model_that_cannot_generate_still_cannot_be_turned_on(tmp_path) -> Non
with pytest.raises(ModelProfileUnavailableError):
store.activate(profile.profile_id, secrets)
+
+
+def _space(store: ModelProfileStore, profile_id: str) -> str:
+ """The embedding space's collection base, as the Runtime names it."""
+ from one_memory.hy_sdk_runtime import vector_collection_bases
+
+ identity = (profile_id, store.require(profile_id, InMemorySecretStore()).revision)
+ return vector_collection_bases(store.snapshot(*identity))[0]
+
+
+def test_a_remote_embedding_must_name_its_endpoint(tmp_path) -> None:
+ """The endpoint no longer follows the generation `base_url`."""
+ from one_memory.model_profiles import EmbeddingBaseUrlRequiredError
+
+ store = ModelProfileStore(tmp_path / "one-memory.sqlite3")
+ secrets = InMemorySecretStore()
+ unnamed = ModelProfileInput(
+ name="Remote",
+ provider_kind=ProviderKind.OPENAI_COMPATIBLE,
+ base_url="https://models.example.com/v1",
+ model="qwen",
+ embedding_model="text-embedding-3-small",
+ api_key=SecretStr(API_KEY),
+ )
+ with pytest.raises(EmbeddingBaseUrlRequiredError):
+ store.create(unnamed, secrets)
+ assert store.list(secrets) == []
+
+ named = store.create(
+ unnamed.model_copy(update={"embedding_base_url": "https://models.example.com/v1"}),
+ secrets,
+ )
+ with pytest.raises(EmbeddingBaseUrlRequiredError):
+ store.update(
+ named.profile_id,
+ ModelProfilePatch(
+ expected_revision=named.revision,
+ embedding_provider_kind=ProviderKind.OLLAMA,
+ embedding_base_url="",
+ ),
+ secrets,
+ )
+
+
+def test_stored_profiles_get_the_endpoint_they_resolved_to_and_keep_their_space(
+ tmp_path,
+) -> None:
+ """An older build stored remote embeddings with a NULL endpoint and resolved
+ it to the generation `base_url` at runtime. Opening the store writes that
+ endpoint in once, so the collection, and the memories in it, stay put; a
+ later edit of the generation endpoint no longer moves them.
+ """
+ from one_memory.hy_sdk_runtime import vector_collection_bases
+
+ database = tmp_path / "one-memory.sqlite3"
+ store = ModelProfileStore(database)
+ secrets = InMemorySecretStore()
+ profile = store.create(
+ ModelProfileInput(
+ name="Remote",
+ provider_kind=ProviderKind.OPENAI_COMPATIBLE,
+ base_url="https://gateway.example.com/v1",
+ model="qwen",
+ embedding_model="text-embedding-3-small",
+ embedding_base_url="https://gateway.example.com/v1",
+ embedding_dimensions=1536,
+ api_key=SecretStr(API_KEY),
+ ),
+ secrets,
+ )
+ identity = (profile.profile_id, profile.revision)
+ # The space the older build's Runtime resolved: `embedding_base_url or base_url`.
+ before = vector_collection_bases(store.snapshot(*identity))[0]
+ with sqlite3.connect(database) as db:
+ # The shape an older build stored.
+ db.execute("UPDATE model_profiles SET embedding_base_url=NULL")
+ db.execute("UPDATE model_profile_versions SET embedding_base_url=NULL")
+
+ migrated = ModelProfileStore(database)
+ assert migrated.snapshot(*identity).embedding_base_url == "https://gateway.example.com/v1"
+ assert _space(migrated, profile.profile_id) == before
+ # Idempotent: opening again changes nothing.
+ assert _space(ModelProfileStore(database), profile.profile_id) == before
+ with sqlite3.connect(database) as db:
+ assert db.execute(
+ "SELECT COUNT(*) FROM model_profile_versions WHERE embedding_base_url IS NULL"
+ ).fetchone() == (0,)
+
+ edited = migrated.update(
+ profile.profile_id,
+ ModelProfilePatch(
+ expected_revision=profile.revision,
+ base_url="https://gateway.example.com/eu/v1",
+ ),
+ secrets,
+ )
+ assert edited.base_url == "https://gateway.example.com/eu/v1"
+ assert edited.embedding_base_url == "https://gateway.example.com/v1"
+ assert _space(migrated, profile.profile_id) == before
diff --git a/memhub/apps/core/tests/test_read_path_freshness_batch.py b/memhub/apps/core/tests/test_read_path_freshness_batch.py
index c4f698a..8ab8fc7 100644
--- a/memhub/apps/core/tests/test_read_path_freshness_batch.py
+++ b/memhub/apps/core/tests/test_read_path_freshness_batch.py
@@ -40,6 +40,7 @@ def library(tmp_path):
provider_kind=ProviderKind.OLLAMA,
model="hy-bot-phi4",
embedding_model="nomic-embed-text",
+ embedding_base_url="http://127.0.0.1:11434",
),
secrets,
)
diff --git a/memhub/apps/web/src/ModelSettings.test.tsx b/memhub/apps/web/src/ModelSettings.test.tsx
index b972fae..655b469 100644
--- a/memhub/apps/web/src/ModelSettings.test.tsx
+++ b/memhub/apps/web/src/ModelSettings.test.tsx
@@ -480,6 +480,30 @@ describe("ModelSettings", () => {
});
});
+ it("writes the prefilled embedding endpoint instead of leaving it to follow generation", async () => {
+ profiles = [
+ {
+ ...profile,
+ embedding_provider_kind: "openai_compatible",
+ embedding_model: "vector-old",
+ embedding_base_url: null,
+ },
+ ];
+ render(<ModelSettings />);
+ await userEvent.click(screen.getByRole("button", { name: "编辑配置" }));
+ await userEvent.clear(screen.getByLabelText("向量模型名"));
+ await userEvent.type(screen.getByLabelText("向量模型名"), "vector-new");
+ await userEvent.click(
+ screen.getByRole("button", { name: "高级:自行配置向量模型" }),
+ );
+ await userEvent.click(screen.getByRole("button", { name: "保存修改" }));
+ expect(update).toHaveBeenCalledWith(profile.profile_id, {
+ expected_revision: 1,
+ embedding_model: "vector-new",
+ embedding_base_url: profile.base_url,
+ });
+ });
+
it("explicitly switches an edited remote embedding to builtin without retaining its dimensions", async () => {
profiles = [
{
diff --git a/memhub/apps/web/src/ModelSettings.tsx b/memhub/apps/web/src/ModelSettings.tsx
index cd5fb4b..e7b1cef 100644
--- a/memhub/apps/web/src/ModelSettings.tsx
+++ b/memhub/apps/web/src/ModelSettings.tsx
@@ -631,10 +631,9 @@ export function ModelSettings({
patch.embedding_model = embeddingModel;
if (embeddingProvider !== editing.embedding_provider_kind)
patch.embedding_provider_kind = embeddingProvider;
- if (
- embeddingBaseUrl !==
- (editing.embedding_base_url ?? editing.base_url ?? "")
- )
+ // Against the stored value only: the field is prefilled with the
+ // generation endpoint, and Core no longer falls back to it.
+ if (embeddingBaseUrl !== (editing.embedding_base_url ?? ""))
patch.embedding_base_url = embeddingBaseUrl;
} else if (
embeddingModeChanged &&
diff --git a/memhub/apps/web/src/OnboardingModelController.tsx b/memhub/apps/web/src/OnboardingModelController.tsx
index 6abbd29..bb6c961 100644
--- a/memhub/apps/web/src/OnboardingModelController.tsx
+++ b/memhub/apps/web/src/OnboardingModelController.tsx
@@ -173,10 +173,15 @@ export function OnboardingModelController({
draft.embedding_mode === "local"
? "bge-small-zh-v1.5"
: draft.embedding_model.trim(),
+ // Core no longer lets the embedding endpoint follow the generation
+ // one, so an empty field is written as the endpoint it means.
embedding_base_url:
draft.embedding_mode === "local"
? null
- : draft.embedding_base_url.trim() || null,
+ : draft.embedding_base_url.trim() ||
+ (draft.embedding_provider_kind === "ollama"
+ ? "http://127.0.0.1:11434"
+ : draft.base_url.trim()),
embedding_dimensions: draft.embedding_mode === "local" ? 512 : null,
};
}