{"record":{"id":"2888b715f5b63e3a","repo":"langgenius/dify","slug":"indexing-technique-is-required-2888b7","errorCode":null,"errorMessage":"indexing_technique is required.","messagePattern":"indexing_technique is required\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"api/controllers/console/datasets/datasets_document.py","lineNumber":557,"sourceCode":"\n        dataset = DatasetService.get_dataset(dataset_id_str, session)\n\n        if not dataset:\n            raise NotFound(\"Dataset not found.\")\n\n        # The role of the current user in the ta table must be admin, owner, or editor\n        if not current_user.is_dataset_editor:\n            raise Forbidden()\n\n        try:\n            DatasetService.check_dataset_permission(dataset, current_user, session)\n        except services.errors.account.NoPermissionError as e:\n            raise Forbidden(str(e))\n\n        knowledge_config = KnowledgeConfig.model_validate(console_ns.payload or {})\n\n        if not dataset.indexing_technique and not knowledge_config.indexing_technique:\n            raise ValueError(\"indexing_technique is required.\")\n\n        # validate args\n        DocumentService.document_create_args_validate(knowledge_config)\n\n        try:\n            documents, batch = DocumentService.save_document_with_dataset_id(\n                dataset, knowledge_config, current_user, session=session\n            )\n            dataset = DatasetService.get_dataset(dataset_id_str, session)\n\n        except ProviderTokenNotInitError as ex:\n            raise ProviderNotInitializeError(ex.description)\n        except QuotaExceededError:\n            raise ProviderQuotaExceededError()\n        except ModelCurrentlyNotSupportError:\n            raise ProviderModelCurrentlyNotSupportError()\n\n        return dump_response(","sourceCodeStart":539,"sourceCodeEnd":575,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/datasets_document.py#L539-L575","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","solutions":["Include indexing_technique in the request body: 'high_quality' (uses embeddings) or 'economical' (keyword only).","If using the UI, ensure the indexing-technique selector is filled on the first upload step.","For an existing dataset that already has indexing_technique set, the field can be omitted on subsequent uploads."],"exampleFix":"// before\nPOST /console/api/datasets/<id>/documents { name: 'doc.txt', data: '...' }\n  →  500 indexing_technique is required.\n\n// after\nPOST /console/api/datasets/<id>/documents {\n  name: 'doc.txt', data: '...', indexing_technique: 'high_quality'\n}  // 200","handlingStrategy":"validation","validationCode":"from services.entities.knowledge_entities.knowledge_entities import KnowledgeConfig\n\ndef indexing_technique_supplied(dataset, payload: dict) -> bool:\n    \"\"\"True when either the dataset already has a technique or the request supplies one.\"\"\"\n    if dataset.indexing_technique:\n        return True\n    try:\n        cfg = KnowledgeConfig.model_validate(payload or {})\n    except Exception:\n        return False\n    return bool(cfg.indexing_technique)\n\nif not indexing_technique_supplied(dataset, request_payload):\n    return BadRequest(\"indexing_technique is required for the first document.\")","typeGuard":"def is_complete_first_upload(dataset, payload: dict) -> bool:\n    \"\"\"True only when the POST will not raise ValueError on indexing_technique.\"\"\"\n    return indexing_technique_supplied(dataset, payload)","tryCatchPattern":"# Translate ValueError into a proper 400 instead of an uncaught 500\ntry:\n    if not dataset.indexing_technique and not knowledge_config.indexing_technique:\n        raise BadRequest(\"indexing_technique is required.\")\nexcept ValueError as e:\n    raise BadRequest(str(e))","preventionTips":["Always send indexing_technique ('high_quality' | 'economical') on the first document POST to a dataset.","Add a request-schema validator (Pydantic field with a Literal default) so the field cannot be silently omitted.","Return a 400 BadRequest for this validation, not an unhandled ValueError that becomes a 500."],"tags":["datasets","validation","indexing","document-upload","rag"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}