Implementation:Langgenius Dify FetchIndexingStatus
| Knowledge Sources | Domains | Last Updated |
|---|---|---|
| Dify | RAG, Knowledge_Management, Frontend | 2026-02-12 00:00 GMT |
Overview
Description
fetchIndexingStatus and fetchIndexingStatusBatch are frontend service functions that retrieve the current processing state of documents being indexed in a Dify knowledge base. fetchIndexingStatus returns the status of a single document, while fetchIndexingStatusBatch returns the status of all documents in a given batch.
These functions are typically called in a polling loop after document upload to drive progress indicators and detect terminal states (completed or error).
Usage
- Poll
fetchIndexingStatusat regular intervals (e.g., every 2--5 seconds) after callingcreateDocumentto track a single document through the pipeline. - Use
fetchIndexingStatusBatchwhen multiple documents were uploaded together, using thebatchID from thecreateDocumentResponse. - Stop polling when
indexing_statusreachescompleted,error, orpaused.
Code Reference
Source Location
web/service/datasets.ts, lines 148--154.
Signature
export const fetchIndexingStatus = (
{ datasetId, documentId }: CommonDocReq
): Promise<IndexingStatusResponse> => {
return get<IndexingStatusResponse>(
`/datasets/${datasetId}/documents/${documentId}/indexing-status`, {}
)
}
export const fetchIndexingStatusBatch = (
{ datasetId, batchId }: BatchReq
): Promise<IndexingStatusBatchResponse> => {
return get<IndexingStatusBatchResponse>(
`/datasets/${datasetId}/batch/${batchId}/indexing-status`, {}
)
}
Import
import { fetchIndexingStatus, fetchIndexingStatusBatch } from '@/service/datasets'
I/O Contract
Inputs
fetchIndexingStatus:
| Parameter | Type | Required | Description |
|---|---|---|---|
datasetId |
string |
Yes | The ID of the dataset containing the document. |
documentId |
string |
Yes | The ID of the document to check. |
fetchIndexingStatusBatch:
| Parameter | Type | Required | Description |
|---|---|---|---|
datasetId |
string |
Yes | The ID of the dataset containing the batch. |
batchId |
string |
Yes | The batch identifier returned from document creation. |
Outputs
fetchIndexingStatus returns Promise<IndexingStatusResponse>:
| Field | Type | Description |
|---|---|---|
id |
string |
Document identifier. |
indexing_status |
DocumentIndexingStatus |
Current status: waiting, parsing, cleaning, splitting, indexing, paused, error, or completed.
|
processing_started_at |
number |
Unix timestamp when processing began. |
parsing_completed_at |
number |
Unix timestamp when parsing finished. |
cleaning_completed_at |
number |
Unix timestamp when cleaning finished. |
splitting_completed_at |
number |
Unix timestamp when splitting finished. |
completed_at |
any |
Unix timestamp when indexing completed (null if not yet complete). |
paused_at |
any |
Unix timestamp when processing was paused (null if not paused). |
error |
any |
Error details if status is error (null otherwise).
|
stopped_at |
any |
Unix timestamp when processing was stopped (null otherwise). |
completed_segments |
number |
Number of segments that have been indexed so far. |
total_segments |
number |
Total number of segments to be indexed. |
fetchIndexingStatusBatch returns Promise<IndexingStatusBatchResponse>:
| Field | Type | Description |
|---|---|---|
data |
IndexingStatusResponse[] |
Array of status records, one per document in the batch. |
Usage Examples
Polling a single document until completion
import { fetchIndexingStatus } from '@/service/datasets'
async function pollUntilComplete(datasetId: string, documentId: string) {
const POLL_INTERVAL = 3000 // 3 seconds
let status = await fetchIndexingStatus({ datasetId, documentId })
while (status.indexing_status !== 'completed' && status.indexing_status !== 'error') {
await new Promise(resolve => setTimeout(resolve, POLL_INTERVAL))
status = await fetchIndexingStatus({ datasetId, documentId })
const progress = status.total_segments > 0
? Math.round((status.completed_segments / status.total_segments) * 100)
: 0
console.log(`Status: ${status.indexing_status}, Progress: ${progress}%`)
}
if (status.indexing_status === 'error') {
console.error('Indexing failed:', status.error)
}
return status
}
Monitoring a batch of documents
import { fetchIndexingStatusBatch } from '@/service/datasets'
const batchStatus = await fetchIndexingStatusBatch({
datasetId: 'ds-abc123',
batchId: 'batch-xyz789',
})
for (const doc of batchStatus.data) {
console.log(`Document ${doc.id}: ${doc.indexing_status} (${doc.completed_segments}/${doc.total_segments})`)
}