{"record":{"id":"5f4df4ffe282d7cd","repo":"langgenius/dify","slug":"embedding-model-and-embedding-model-provider-are-r","errorCode":null,"errorMessage":"embedding model and embedding model provider are required for high quality indexing.","messagePattern":"embedding model and embedding model provider are required for high quality indexing\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"api/controllers/console/datasets/datasets_document.py","lineNumber":645,"sourceCode":"    )\n    @console_ns.response(400, \"Invalid request parameters\")\n    @setup_required\n    @login_required\n    @account_initialization_required\n    @cloud_edition_billing_resource_check(\"vector_space\")\n    @cloud_edition_billing_rate_limit_check(\"knowledge\")\n    @with_current_user\n    @with_current_tenant_id\n    @with_session\n    def post(self, session: Session, current_tenant_id: str, current_user: Account):\n        # The role of the current user in the ta table must be admin, owner, dataset_operator, or editor\n        if not current_user.is_dataset_editor:\n            raise Forbidden()\n\n        knowledge_config = KnowledgeConfig.model_validate(console_ns.payload or {})\n        if knowledge_config.indexing_technique == IndexTechniqueType.HIGH_QUALITY:\n            if knowledge_config.embedding_model is None or knowledge_config.embedding_model_provider is None:\n                raise ValueError(\"embedding model and embedding model provider are required for high quality indexing.\")\n            try:\n                model_manager = ModelManager.for_tenant(tenant_id=current_tenant_id)\n                model_manager.get_model_instance(\n                    tenant_id=current_tenant_id,\n                    provider=knowledge_config.embedding_model_provider,\n                    model_type=ModelType.TEXT_EMBEDDING,\n                    model=knowledge_config.embedding_model,\n                )\n                is_multimodal = DatasetService.check_is_multimodal_model(\n                    current_tenant_id, knowledge_config.embedding_model_provider, knowledge_config.embedding_model\n                )\n                knowledge_config.is_multimodal = is_multimodal  # pyrefly: ignore[bad-assignment]\n            except InvokeAuthorizationError:\n                raise ProviderNotInitializeError(\n                    \"No Embedding Model available. Please configure a valid provider in the Settings -> Model Provider.\"\n                )\n            except ProviderTokenNotInitError as ex:\n                raise ProviderNotInitializeError(ex.description)","sourceCodeStart":627,"sourceCodeEnd":663,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/datasets_document.py#L627-L663","documentation":"Built-in ValueError (uncaught -> HTTP 500) raised in POST /datasets/init when indexing_technique is IndexTechniqueType.HIGH_QUALITY but KnowledgeConfig.embedding_model or embedding_model_provider is None. Pydantic model_validate already accepted the partial config, so this is the controller's secondary structural check for high-quality indexing.","triggerScenarios":"POST /console/api/datasets/init with body {\"indexing_technique\":\"high_quality\"} omitting embedding_model and/or embedding_model_provider.","commonSituations":"Hand-built API payload or SDK call that drops the model fields; UI regression after switching indexing_technique from economical to high_quality without re-selecting the model; integration test fixture missing the fields.","solutions":["When indexing_technique is high_quality, always include both embedding_model and embedding_model_provider in the body.","If you don't need high quality, use indexing_technique:\"economical\" to skip the embedding-model requirement.","Validate the payload against the KnowledgeConfig schema client-side before sending.","Wrap the controller check in a 400-mapped exception (BadRequest) instead of raising raw ValueError so callers see a structured error."],"exampleFix":"// before\nconst body = { indexing_technique: 'high_quality', data_source: {...} };\nawait fetch('/console/api/datasets/init', { method:'POST', body: JSON.stringify(body) });\n\n// after\nconst body = {\n  indexing_technique: 'high_quality',\n  embedding_model: 'text-embedding-3-small',\n  embedding_model_provider: 'langgenius/openai/openai',\n  data_source: {...},\n};\nawait fetch('/console/api/datasets/init', { method:'POST', body: JSON.stringify(body) });","handlingStrategy":"validation","validationCode":"def validate_init_payload(body: dict) -> None:\n    if body.get('indexing_technique') == 'high_quality':\n        missing = [f for f in ('embedding_model', 'embedding_model_provider') if not body.get(f)]\n        if missing:\n            raise ValueError(f'high_quality init requires: {missing}')\n\nvalidate_init_payload(body)\nrequests.post(f\"{base}/console/api/datasets/init\", headers=hdrs, json=body)","typeGuard":"def is_high_quality_payload(body: dict) -> bool:\n    return (\n        isinstance(body, dict)\n        and body.get('indexing_technique') == 'high_quality'\n        and bool(body.get('embedding_model'))\n        and bool(body.get('embedding_model_provider'))\n    )","tryCatchPattern":"try:\n    resp = requests.post(f\"{base}/console/api/datasets/init\", headers=hdrs, json=body)\n    resp.raise_for_status()\nexcept requests.HTTPError as e:\n    if 'embedding model and embedding model provider are required' in e.response.text:\n        body.setdefault('embedding_model', DEFAULT_EMBEDDING_MODEL)\n        body.setdefault('embedding_model_provider', DEFAULT_EMBEDDING_PROVIDER)\n        # re-send once with defaults\n        resp = requests.post(f\"{base}/console/api/datasets/init\", headers=hdrs, json=body)\n    else:\n        raise","preventionTips":["Always send embedding_model + embedding_model_provider when indexing_technique is high_quality.","Use 'economical' when you don't need embeddings.","Validate the payload against the KnowledgeConfig schema client-side.","Keep a typed client (Pydantic / TS interface) for the request body."],"tags":["validation","datasets","embedding-model","request-payload","init"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}