langgenius/dify · error · ValueError

embedding model and embedding model provider are required fo

Error message

embedding model and embedding model provider are required for high quality indexing.

What it means

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.

Source

Thrown at api/controllers/console/datasets/datasets_document.py:645

    )
    @console_ns.response(400, "Invalid request parameters")
    @setup_required
    @login_required
    @account_initialization_required
    @cloud_edition_billing_resource_check("vector_space")
    @cloud_edition_billing_rate_limit_check("knowledge")
    @with_current_user
    @with_current_tenant_id
    @with_session
    def post(self, session: Session, current_tenant_id: str, current_user: Account):
        # The role of the current user in the ta table must be admin, owner, dataset_operator, or editor
        if not current_user.is_dataset_editor:
            raise Forbidden()

        knowledge_config = KnowledgeConfig.model_validate(console_ns.payload or {})
        if knowledge_config.indexing_technique == IndexTechniqueType.HIGH_QUALITY:
            if knowledge_config.embedding_model is None or knowledge_config.embedding_model_provider is None:
                raise ValueError("embedding model and embedding model provider are required for high quality indexing.")
            try:
                model_manager = ModelManager.for_tenant(tenant_id=current_tenant_id)
                model_manager.get_model_instance(
                    tenant_id=current_tenant_id,
                    provider=knowledge_config.embedding_model_provider,
                    model_type=ModelType.TEXT_EMBEDDING,
                    model=knowledge_config.embedding_model,
                )
                is_multimodal = DatasetService.check_is_multimodal_model(
                    current_tenant_id, knowledge_config.embedding_model_provider, knowledge_config.embedding_model
                )
                knowledge_config.is_multimodal = is_multimodal  # pyrefly: ignore[bad-assignment]
            except InvokeAuthorizationError:
                raise ProviderNotInitializeError(
                    "No Embedding Model available. Please configure a valid provider in the Settings -> Model Provider."
                )
            except ProviderTokenNotInitError as ex:
                raise ProviderNotInitializeError(ex.description)

View on GitHub (pinned to ef8544b173)

Solutions

  1. When indexing_technique is high_quality, always include both embedding_model and embedding_model_provider in the body.
  2. If you don't need high quality, use indexing_technique:"economical" to skip the embedding-model requirement.
  3. Validate the payload against the KnowledgeConfig schema client-side before sending.
  4. Wrap the controller check in a 400-mapped exception (BadRequest) instead of raising raw ValueError so callers see a structured error.

Example fix

// before
const body = { indexing_technique: 'high_quality', data_source: {...} };
await fetch('/console/api/datasets/init', { method:'POST', body: JSON.stringify(body) });

// after
const body = {
  indexing_technique: 'high_quality',
  embedding_model: 'text-embedding-3-small',
  embedding_model_provider: 'langgenius/openai/openai',
  data_source: {...},
};
await fetch('/console/api/datasets/init', { method:'POST', body: JSON.stringify(body) });
Defensive patterns

Strategy: validation

Validate before calling

def validate_init_payload(body: dict) -> None:
    if body.get('indexing_technique') == 'high_quality':
        missing = [f for f in ('embedding_model', 'embedding_model_provider') if not body.get(f)]
        if missing:
            raise ValueError(f'high_quality init requires: {missing}')

validate_init_payload(body)
requests.post(f"{base}/console/api/datasets/init", headers=hdrs, json=body)

Type guard

def is_high_quality_payload(body: dict) -> bool:
    return (
        isinstance(body, dict)
        and body.get('indexing_technique') == 'high_quality'
        and bool(body.get('embedding_model'))
        and bool(body.get('embedding_model_provider'))
    )

Try / catch

try:
    resp = requests.post(f"{base}/console/api/datasets/init", headers=hdrs, json=body)
    resp.raise_for_status()
except requests.HTTPError as e:
    if 'embedding model and embedding model provider are required' in e.response.text:
        body.setdefault('embedding_model', DEFAULT_EMBEDDING_MODEL)
        body.setdefault('embedding_model_provider', DEFAULT_EMBEDDING_PROVIDER)
        # re-send once with defaults
        resp = requests.post(f"{base}/console/api/datasets/init", headers=hdrs, json=body)
    else:
        raise

Prevention

When it happens

Trigger: POST /console/api/datasets/init with body {"indexing_technique":"high_quality"} omitting embedding_model and/or embedding_model_provider.

Common situations: 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.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/5f4df4ffe282d7cd. Report an issue: GitHub.