langgenius/dify · error · NotFound

Document not found.

Error message

Document not found.

What it means

Raised after the dataset check passes but DocumentService.get_document returns None for the (dataset_id, document_id) pair. The document is not part of the dataset, was deleted, or the id is wrong; the controller returns NotFound.

Source

Thrown at api/controllers/console/datasets/datasets_segments.py:724

        self,
        req_data: ChildChunkCreatePayload,
        session: Session,
        current_tenant_id: str,
        current_user: Account,
        dataset_id: UUID,
        document_id: UUID,
        segment_id: UUID,
    ):
        # check dataset
        dataset_id_str = str(dataset_id)
        dataset = DatasetService.get_dataset(dataset_id_str, session)
        if not dataset:
            raise NotFound("Dataset not found.")
        # check document
        document_id_str = str(document_id)
        document = DocumentService.get_document(dataset_id_str, document_id_str, session=session)
        if not document:
            raise NotFound("Document not found.")
        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))
        # check embedding model setting
        if dataset.indexing_technique == IndexTechniqueType.HIGH_QUALITY:
            try:
                model_manager = ModelManager.for_tenant(tenant_id=current_tenant_id)
                model_manager.get_model_instance(
                    tenant_id=current_tenant_id,
                    provider=dataset.embedding_model_provider,
                    model_type=ModelType.TEXT_EMBEDDING,
                    model=dataset.embedding_model,
                )
            except LLMBadRequestError:
                raise ProviderNotInitializeError(

View on GitHub (pinned to ef8544b173)

Solutions

  1. List documents under the dataset to confirm the document_id belongs to it.
  2. If the document was deleted, choose an existing document or re-upload it.
  3. Reload the document tree in the UI before performing child-chunk operations.

Example fix

// before
POST /datasets/{ds}/documents/{deleted_doc}/segments/{seg}/child_chunks
// after
GET /datasets/{ds}/documents -> pick existing document_id
POST /datasets/{ds}/documents/{existing_doc}/segments/{seg}/child_chunks
Defensive patterns

Strategy: validation

Validate before calling

async function ensureDocument(datasetId, documentId) {
  const r = await fetch(`/console/api/datasets/${datasetId}/documents/${documentId}`);
  if (!r.ok) throw new Error('document not found under dataset');
  return r.json();
}

Type guard

const isValidDocumentId = (id) => typeof id === 'string' && /^[0-9a-fA-F-]{36}$/.test(id);

Try / catch

try {
  await ensureDocument(datasetId, documentId);
  await createChildChunk({...});
} catch (e) { if (e.status === 404) throw new Error('reload document and retry'); throw e; }

Prevention

When it happens

Trigger: POST .../segments/{segment_id}/child_chunks with a document_id that is not a child of the given dataset, was deleted, or is malformed.

Common situations: Document was removed after the page was loaded; cross-dataset document id reused from another context; document is in a 'paused' or filtered state that hides it.

Related errors


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