{"record":{"id":"12d46623a90d7ff4","repo":"unslothai/unsloth","slug":"embedding-model-must-be-a-hugging-face-repo-id-e","errorCode":null,"errorMessage":"Embedding model must be a Hugging Face repo id (e.g. 'unsloth/bge-small-en-v1.5') or a local model path, up to {MAX_EMBEDDING_MODEL_LENGTH} characters.","messagePattern":"Embedding model must be a Hugging Face repo id \\(e\\.g\\. 'unsloth/bge-small-en-v1\\.5'\\) or a local model path, up to (.+?) characters\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/utils/embedding_model_settings.py","lineNumber":62,"sourceCode":"    return config.EMBEDDING_MODEL\n\n\ndef _coerce_embedding_model(value: Any) -> str | None:\n    if not isinstance(value, str):\n        return None\n    cleaned = value.strip()\n    if not cleaned or len(cleaned) > MAX_EMBEDDING_MODEL_LENGTH:\n        return None\n    # Newlines/control chars are never valid in a repo id or path.\n    if any(ord(ch) < 32 for ch in cleaned):\n        return None\n    return cleaned\n\n\ndef validate_embedding_model(value: Any) -> str:\n    cleaned = _coerce_embedding_model(value)\n    if cleaned is None:\n        raise ValueError(\n            \"Embedding model must be a Hugging Face repo id (e.g. \"\n            \"'unsloth/bge-small-en-v1.5') or a local model path, up to \"\n            f\"{MAX_EMBEDDING_MODEL_LENGTH} characters.\"\n        )\n    return cleaned\n\n\ndef get_stored_embedding_model() -> str | None:\n    \"\"\"The persisted override, or None when unset/invalid.\"\"\"\n    global _cached\n    now = time.monotonic()\n    with _lock:\n        cached = _cached\n        if cached is not None and now - cached[0] < _CACHE_TTL_S:\n            return cached[1]\n        gen = _generation\n    try:\n        from storage.studio_db import get_app_setting","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/utils/embedding_model_settings.py#L44-L80","documentation":"Raised by validate_embedding_model when the stored/configured embedding model value fails _coerce_embedding_model: it must be a non-empty string (or string-coercible) that is <= MAX_EMBEDDING_MODEL_LENGTH characters, strips to non-empty, and contains no control characters (any codepoint < 32, including newlines). These constraints match valid HF repo ids or local paths.","triggerScenarios":"Calling validate_embedding_model (or a settings API that persists the embedding model) with '', whitespace-only strings, values longer than MAX_EMBEDDING_MODEL_LENGTH, non-string junk (dict/list coerced badly), or strings containing \\n / \\t / other control chars.","commonSituations":"UI form submitted with an empty field; copy-paste of a model id that includes a trailing newline or embedded tab; a path with a stray carriage return from Windows line endings; an absurdly long pasted blob instead of a repo id.","solutions":["Set the value to a valid HF repo id like 'unsloth/bge-small-en-v1.5' or an absolute local model path.","Trim whitespace and remove newlines/tabs from the input before saving (the validator strips outer whitespace but rejects embedded control chars).","Verify length is within MAX_EMBEDDING_MODEL_LENGTH.","If it came from a config file, check the file for multiline YAML block scalars accidentally producing embedded newlines."],"exampleFix":"# before\nset_embedding_model(\"unsloth/bge-small-en-v1.5\\n\")  # trailing newline -> ValueError\n\n# after\nset_embedding_model(\"unsloth/bge-small-en-v1.5\".strip())","handlingStrategy":"validation","validationCode":"MAX_LEN = 200  # keep in sync with MAX_EMBEDDING_MODEL_LENGTH\n\ndef is_valid_embedding_model(value) -> bool:\n    if not isinstance(value, str):\n        return False\n    v = value.strip()\n    return (\n        0 < len(v) <= MAX_LEN\n        and all(ord(ch) >= 32 for ch in v)\n    )\n\n# guard: assert is_valid_embedding_model(model_id) before set_embedding_model(model_id)","typeGuard":"def is_valid_embedding_model(value: object) -> bool:\n    if not isinstance(value, str):\n        return False\n    v = value.strip()\n    return bool(v) and len(v) <= 200 and all(ord(c) >= 32 for c in v)","tryCatchPattern":"try:\n    validate_embedding_model(raw)\nexcept ValueError:\n    raise ValueError(f\"Embedding model '{raw!r}' is not a valid HF repo id or path\") from None","preventionTips":["Strip whitespace/newlines from pasted model ids before saving.","Use HF repo ids (org/name) or absolute local paths — nothing else is valid.","Reject empty form submissions client-side before they reach the settings API.","Keep inputs under MAX_EMBEDDING_MODEL_LENGTH characters."],"tags":["settings","embedding","validation","config"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}