Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Python && Go: fix parse status (#18841)

Jin Haid37486e295d5
diff --git a/api/apps/restful_apis/chunk_api.py b/api/apps/restful_apis/chunk_api.py
index b157e78be9..ddd7f7979c 100644
--- a/api/apps/restful_apis/chunk_api.py
+++ b/api/apps/restful_apis/chunk_api.py
@@ -123,13 +123,7 @@ def _map_doc(doc):
"token_num": "token_count",
"parser_id": "chunk_method",
}
- run_mapping = {
- "0": "UNSTART",
- "1": "RUNNING",
- "2": "CANCEL",
- "3": "DONE",
- "4": "FAIL",
- }
+ run_mapping = {status.value: status.name for status in TaskStatus}
renamed_doc = {}
for key, value in doc.to_dict().items():
renamed_doc[key_mapping.get(key, key)] = value
diff --git a/api/apps/restful_apis/document_api.py b/api/apps/restful_apis/document_api.py
index 9d25875238..78cb021670 100644
--- a/api/apps/restful_apis/document_api.py
+++ b/api/apps/restful_apis/document_api.py
@@ -792,7 +792,7 @@ def list_docs(dataset_id, tenant_id):
items:
type: string
required: false
- description: Filter by document run status. Supports both numeric ("0", "1", "2", "3", "4") and text formats ("UNSTART", "RUNNING", "CANCEL", "DONE", "FAIL").
+ description: Filter by document run status. Supports both numeric ("0", "1", "2", "3", "4", "5") and text formats ("UNSTART", "RUNNING", "CANCEL", "DONE", "FAIL", "SCHEDULE").
- in: header
name: Authorization
type: string
diff --git a/api/apps/services/document_api_service.py b/api/apps/services/document_api_service.py
index e8f7ab78a9..aa4663661a 100644
--- a/api/apps/services/document_api_service.py
+++ b/api/apps/services/document_api_service.py
@@ -298,17 +298,11 @@ def _process_run_mapping(doc, run_status):
Returns:
A dictionary with renamed keys for API response.
"""
- run_mapping = {
- "0": "UNSTART",
- "1": "RUNNING",
- "2": "CANCEL",
- "3": "DONE",
- "4": "FAIL",
- }
+ run_mapping = {status.value: status.name for status in TaskStatus}
# Handle run field
- if run_status is None or run_status not in run_mapping.keys():
- run_status = "0"
+ if run_status is None or str(run_status) not in run_mapping:
+ run_status = TaskStatus.UNSTART.value
- doc["run"] = run_mapping[run_status]
+ doc["run"] = run_mapping[str(run_status)]
return doc
diff --git a/docs/references/http_api_reference.md b/docs/references/http_api_reference.md
index 3fd8fa9a8d..250c47363d 100644
--- a/docs/references/http_api_reference.md
+++ b/docs/references/http_api_reference.md
@@ -1787,8 +1787,8 @@ curl --request GET \
Filter by file suffix. Supports multiple values, e.g., `pdf`, `txt`, and `docx`. Defaults to all suffixes.
- `run`: (*Filter parameter*), `array[string]`
Filter by document processing status. Supports numeric, text, and mixed formats:
- - Numeric format: `["0", "1", "2", "3", "4"]`
- - Text format: `[UNSTART, RUNNING, CANCEL, DONE, FAIL]`
+ - Numeric format: `["0", "1", "2", "3", "4", "5"]`
+ - Text format: `[UNSTART, RUNNING, CANCEL, DONE, FAIL, SCHEDULE]`
- Mixed format: `[UNSTART, 1, DONE]` (mixing numeric and text formats)
- Status mapping:
- `0` / `UNSTART`: Document not yet processed
@@ -1796,6 +1796,7 @@ curl --request GET \
- `2` / `CANCEL`: Document processing was canceled
- `3` / `DONE`: Document processing completed successfully
- `4` / `FAIL`: Document processing failed
+ - `5` / `SCHEDULE`: Document is scheduled and waiting to be processed
Defaults to all statuses.
- `metadata_condition`: (*Filter parameter*), `object` (JSON in query)
Optional metadata filter applied to documents when `document_ids` is not provided. Uses the same structure as retrieval:
diff --git a/internal/service/chunk/chunk.go b/internal/service/chunk/chunk.go
index 00982dc7f4..d50fcc5b9d 100644
--- a/internal/service/chunk/chunk.go
+++ b/internal/service/chunk/chunk.go
@@ -29,6 +29,7 @@ import (
"ragflow/internal/common"
"ragflow/internal/entity"
"ragflow/internal/entity/models"
+ "ragflow/internal/service"
"strings"
"sync"
"time"
@@ -43,7 +44,6 @@ import (
"ragflow/internal/engine"
"ragflow/internal/engine/types"
"ragflow/internal/ingestion/knowledge_compile"
- "ragflow/internal/service"
"ragflow/internal/service/document"
"ragflow/internal/service/nlp"
"ragflow/internal/storage"
@@ -1001,7 +1001,7 @@ func (s *ChunkService) List(ctx context.Context, req *service.ListChunksRequest,
"process_duration": doc.ProcessDuration,
"content_hash": doc.ContentHash,
"suffix": doc.Suffix,
- "run": chunkDocRunText(doc.Run),
+ "run": service.ChunkDocRunText(doc.Run),
"status": doc.Status,
"create_time": doc.CreateTime,
"create_date": utility.FormatTimeToString(doc.CreateDate, timeFormat),
@@ -1747,24 +1747,3 @@ func releaseChunkImageMergeLock(key string) {
delete(chunkImageMergeLocks.locks, key)
}
}
-
-// chunkDocRunText maps the document run code to its text form, mirroring
-// Python's _map_doc run_mapping.
-func chunkDocRunText(run *string) interface{} {
- if run == nil {
- return nil
- }
- switch *run {
- case "0":
- return "UNSTART"
- case "1":
- return "RUNNING"
- case "2":
- return "CANCEL"
- case "3":
- return "DONE"
- case "4":
- return "FAIL"
- }
- return *run
-}
diff --git a/internal/service/chunk_types.go b/internal/service/chunk_types.go
index 41f2cab058..d8d86afeee 100644
--- a/internal/service/chunk_types.go
+++ b/internal/service/chunk_types.go
@@ -488,7 +488,7 @@ func (s *ChunkService) List(ctx context.Context, req *ListChunksRequest, userID
"process_duration": doc.ProcessDuration,
"content_hash": doc.ContentHash,
"suffix": doc.Suffix,
- "run": chunkDocRunText(doc.Run),
+ "run": ChunkDocRunText(doc.Run),
"status": doc.Status,
"create_time": doc.CreateTime,
"create_date": utility.FormatTimeToString(doc.CreateDate, timeFormat),
@@ -785,7 +785,7 @@ func (s *ChunkService) RemoveChunks(ctx context.Context, req *RemoveChunksReques
}
if deletedCount > 0 {
- if err := s.decrementChunkStats(req.DocID, doc.KbID, 0, deletedCount, 0); err != nil {
+ if err = s.decrementChunkStats(req.DocID, doc.KbID, 0, deletedCount, 0); err != nil {
return deletedCount, fmt.Errorf("failed to update chunk stats: %w", err)
}
}
@@ -938,7 +938,7 @@ func isInternalField(k string) bool {
// ListChunks. Returns true if the field was handled.
// chunkDocRunText maps the document run code to its text form, mirroring
// Python's _map_doc run_mapping.
-func chunkDocRunText(run *string) interface{} {
+func ChunkDocRunText(run *string) interface{} {
if run == nil {
return nil
}
@@ -953,6 +953,8 @@ func chunkDocRunText(run *string) interface{} {
return "DONE"
case "4":
return "FAIL"
+ case "5":
+ return "SCHEDULE"
}
return *run
}
diff --git a/internal/service/chunk_types_test.go b/internal/service/chunk_types_test.go
index f5e8d1f048..e8d56ce93d 100644
--- a/internal/service/chunk_types_test.go
+++ b/internal/service/chunk_types_test.go
@@ -231,7 +231,7 @@ func TestChunkTypesDecrementChunkStats(t *testing.T) {
if err != nil {
t.Fatalf("open sqlite: %v", err)
}
- if err := db.AutoMigrate(&entity.Knowledgebase{}, &entity.Document{}); err != nil {
+ if err = db.AutoMigrate(&entity.Knowledgebase{}, &entity.Document{}); err != nil {
t.Fatalf("migrate sqlite: %v", err)
}
previousDB := dao.DB
@@ -239,7 +239,7 @@ func TestChunkTypesDecrementChunkStats(t *testing.T) {
t.Cleanup(func() { dao.DB = previousDB })
status := string(entity.StatusValid)
- if err := dao.DB.Create(&entity.Knowledgebase{
+ if err = dao.DB.Create(&entity.Knowledgebase{
ID: "kb-1",
TenantID: "tenant-1",
Name: "kb-1",
@@ -253,7 +253,7 @@ func TestChunkTypesDecrementChunkStats(t *testing.T) {
}).Error; err != nil {
t.Fatalf("create kb: %v", err)
}
- if err := dao.DB.Create(&entity.Document{
+ if err = dao.DB.Create(&entity.Document{
ID: "doc-1",
KbID: "kb-1",
ParserID: string(entity.ParserTypeNaive),
@@ -270,35 +270,35 @@ func TestChunkTypesDecrementChunkStats(t *testing.T) {
}
svc := &ChunkService{}
- if err := svc.decrementChunkStats("doc-1", "kb-1", 0, 2, 0); err != nil {
+ if err = svc.decrementChunkStats("doc-1", "kb-1", 0, 2, 0); err != nil {
t.Fatalf("decrementChunkStats() error = %v", err)
}
var doc entity.Document
- if err := dao.DB.First(&doc, "id = ?", "doc-1").Error; err != nil {
+ if err = dao.DB.First(&doc, "id = ?", "doc-1").Error; err != nil {
t.Fatalf("get doc: %v", err)
}
if doc.TokenNum != 10 || doc.ChunkNum != 1 {
t.Fatalf("document stats token=%d chunk=%d, want token=10 chunk=1", doc.TokenNum, doc.ChunkNum)
}
var kb entity.Knowledgebase
- if err := dao.DB.First(&kb, "id = ?", "kb-1").Error; err != nil {
+ if err = dao.DB.First(&kb, "id = ?", "kb-1").Error; err != nil {
t.Fatalf("get kb: %v", err)
}
if kb.TokenNum != 20 || kb.ChunkNum != 3 {
t.Fatalf("knowledgebase stats token=%d chunk=%d, want token=20 chunk=3", kb.TokenNum, kb.ChunkNum)
}
- if err := svc.decrementChunkStats("doc-1", "kb-1", 30, 30, -1); err != nil {
+ if err = svc.decrementChunkStats("doc-1", "kb-1", 30, 30, -1); err != nil {
t.Fatalf("decrementChunkStats() clamp error = %v", err)
}
- if err := dao.DB.First(&doc, "id = ?", "doc-1").Error; err != nil {
+ if err = dao.DB.First(&doc, "id = ?", "doc-1").Error; err != nil {
t.Fatalf("get doc after clamp: %v", err)
}
if doc.TokenNum != 0 || doc.ChunkNum != 0 || doc.ProcessDuration != 0 {
t.Fatalf("document clamped stats token=%d chunk=%d duration=%v, want zeros", doc.TokenNum, doc.ChunkNum, doc.ProcessDuration)
}
- if err := dao.DB.First(&kb, "id = ?", "kb-1").Error; err != nil {
+ if err = dao.DB.First(&kb, "id = ?", "kb-1").Error; err != nil {
t.Fatalf("get kb after clamp: %v", err)
}
if kb.TokenNum != 0 || kb.ChunkNum != 0 {
@@ -479,3 +479,29 @@ func TestApplyCommonChunkMapping(t *testing.T) {
t.Error("result should be empty for unhandled field")
}
}
+
+func TestChunkDocRunText(t *testing.T) {
+ strPtr := func(s string) *string { return &s }
+ cases := []struct {
+ name string
+ run *string
+ want interface{}
+ }{
+ {name: "nil returns nil", run: nil, want: nil},
+ {name: "0 UNSTART", run: strPtr("0"), want: "UNSTART"},
+ {name: "1 RUNNING", run: strPtr("1"), want: "RUNNING"},
+ {name: "2 CANCEL", run: strPtr("2"), want: "CANCEL"},
+ {name: "3 DONE", run: strPtr("3"), want: "DONE"},
+ {name: "4 FAIL", run: strPtr("4"), want: "FAIL"},
+ {name: "5 SCHEDULE", run: strPtr("5"), want: "SCHEDULE"},
+ {name: "unknown returns raw", run: strPtr("999"), want: "999"},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ got := ChunkDocRunText(tc.run)
+ if got != tc.want {
+ t.Fatalf("chunkDocRunText(%v) = %v, want %v", tc.run, got, tc.want)
+ }
+ })
+ }
+}
diff --git a/tools/scripts/rename_models_providers.py b/tools/scripts/rename_models_providers.py
index 6538e82097..6e66f9123e 100644
--- a/tools/scripts/rename_models_providers.py
+++ b/tools/scripts/rename_models_providers.py
@@ -1,35 +1,38 @@
#!/usr/bin/env python3
"""Rename provider name fields in conf/models/*.json to match llm_factories.json."""
-import json, os
+
+import json
+import os
REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
MODELS_DIR = os.path.join(REPO_ROOT, "conf", "models")
# Valid mappings: models current name → llm_factories name
CHANGES = {
- "avian": "Avian",
- "Baichuan": "BaiChuan",
- "Baidu": "BaiduYiyan",
- "CoHere": "Cohere",
- "FishAudio": "Fish Audio",
- "Gitee": "GiteeAI",
- "Google": "Gemini",
- "JieKouAI": "Jiekou.AI",
- "lmstudio": "LM-Studio",
- "localai": "LocalAI",
- "modelscope": "ModelScope",
- "Novita": "NovitaAI",
- "Nvidia": "NVIDIA",
- "ollama": "Ollama",
- "SiliconFlow": "SILICONFLOW",
- "HunYuan": "Tencent Hunyuan",
- "Aliyun": "Tongyi-Qianwen",
- "vllm": "VLLM",
- "Voyage": "Voyage AI",
- "xinference": "Xinference",
- "XunFei": "XunFei Spark",
+ "avian": "Avian",
+ "Baichuan": "BaiChuan",
+ "Baidu": "BaiduYiyan",
+ "CoHere": "Cohere",
+ "FishAudio": "Fish Audio",
+ "Gitee": "GiteeAI",
+ "Google": "Gemini",
+ "JieKouAI": "Jiekou.AI",
+ "lmstudio": "LM-Studio",
+ "localai": "LocalAI",
+ "modelscope": "ModelScope",
+ "Novita": "NovitaAI",
+ "Nvidia": "NVIDIA",
+ "ollama": "Ollama",
+ "SiliconFlow": "SILICONFLOW",
+ "HunYuan": "Tencent Hunyuan",
+ "Aliyun": "Tongyi-Qianwen",
+ "vllm": "VLLM",
+ "Voyage": "Voyage AI",
+ "xinference": "Xinference",
+ "XunFei": "XunFei Spark",
}
+
def main():
# Build current name → filename mapping
file_map = {}
@@ -51,5 +54,6 @@ def main():
f.write("\n")
print(f'{fn}: "{old_name}" -> "{new_name}"')
+
if __name__ == "__main__":
main()