langgenius/dify · error · ValueError

indexing_technique is required.

Error message

indexing_technique is required.

What it means

Uncaught Python ValueError (surfaces as HTTP 500 in Flask-RESTx unless a global handler maps it) raised in DatasetDocumentListApi.post when both dataset.indexing_technique and the request's knowledge_config.indexing_technique are empty/None. The endpoint requires an indexing technique on the first document of a dataset (high_quality vs economical) to know whether embeddings are needed.

Source

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

        dataset = DatasetService.get_dataset(dataset_id_str, session)

        if not dataset:
            raise NotFound("Dataset not found.")

        # The role of the current user in the ta table must be admin, owner, or editor
        if not current_user.is_dataset_editor:
            raise Forbidden()

        try:
            DatasetService.check_dataset_permission(dataset, current_user, session)
        except services.errors.account.NoPermissionError as e:
            raise Forbidden(str(e))

        knowledge_config = KnowledgeConfig.model_validate(console_ns.payload or {})

        if not dataset.indexing_technique and not knowledge_config.indexing_technique:
            raise ValueError("indexing_technique is required.")

        # validate args
        DocumentService.document_create_args_validate(knowledge_config)

        try:
            documents, batch = DocumentService.save_document_with_dataset_id(
                dataset, knowledge_config, current_user, session=session
            )
            dataset = DatasetService.get_dataset(dataset_id_str, session)

        except ProviderTokenNotInitError as ex:
            raise ProviderNotInitializeError(ex.description)
        except QuotaExceededError:
            raise ProviderQuotaExceededError()
        except ModelCurrentlyNotSupportError:
            raise ProviderModelCurrentlyNotSupportError()

        return dump_response(

View on GitHub (pinned to ef8544b173)

Solutions

  1. Include indexing_technique in the request body: 'high_quality' (uses embeddings) or 'economical' (keyword only).
  2. If using the UI, ensure the indexing-technique selector is filled on the first upload step.
  3. For an existing dataset that already has indexing_technique set, the field can be omitted on subsequent uploads.

Example fix

// before
POST /console/api/datasets/<id>/documents { name: 'doc.txt', data: '...' }
  →  500 indexing_technique is required.

// after
POST /console/api/datasets/<id>/documents {
  name: 'doc.txt', data: '...', indexing_technique: 'high_quality'
}  // 200
Defensive patterns

Strategy: validation

Validate before calling

from services.entities.knowledge_entities.knowledge_entities import KnowledgeConfig

def indexing_technique_supplied(dataset, payload: dict) -> bool:
    """True when either the dataset already has a technique or the request supplies one."""
    if dataset.indexing_technique:
        return True
    try:
        cfg = KnowledgeConfig.model_validate(payload or {})
    except Exception:
        return False
    return bool(cfg.indexing_technique)

if not indexing_technique_supplied(dataset, request_payload):
    return BadRequest("indexing_technique is required for the first document.")

Type guard

def is_complete_first_upload(dataset, payload: dict) -> bool:
    """True only when the POST will not raise ValueError on indexing_technique."""
    return indexing_technique_supplied(dataset, payload)

Try / catch

# Translate ValueError into a proper 400 instead of an uncaught 500
try:
    if not dataset.indexing_technique and not knowledge_config.indexing_technique:
        raise BadRequest("indexing_technique is required.")
except ValueError as e:
    raise BadRequest(str(e))

Prevention

When it happens

Trigger: POST /console/api/datasets/<dataset_id>/documents where the dataset has no indexing_technique set yet (first upload) AND the payload's KnowledgeConfig.indexing_technique is omitted or null. The check is `if not dataset.indexing_technique and not knowledge_config.indexing_technique`.

Common situations: Creating the first document in a newly created dataset without specifying indexing_technique in the body; frontend form bug that drops the field; API client that assumes a default where none exists.

Related errors


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