Skip to content

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

feat(parser): unify BuiltIn and Pipeline parser selection into one dropdown (#20603)

xugangqiangb75e195f222c
diff --git a/internal/cli/user_command.go b/internal/cli/user_command.go
index 280ee08cdf..5651064006 100644
--- a/internal/cli/user_command.go
+++ b/internal/cli/user_command.go
@@ -661,7 +661,9 @@ func (c *CLI) APICreateDatasetCommand(commandCount int, cmd *Command) (ResponseI
}
payload := map[string]interface{}{
- "name": datasetName,
+ "name": datasetName,
+ "parse_type": 1,
+ "parser_id": "general",
}
resp, err := httpClient.Request(commandCount, "POST", "/datasets", httpClient.AuthKind(), nil, payload)
diff --git a/internal/service/dataset/create_test.go b/internal/service/dataset/create_test.go
index 791d466960..cf2e14b5cc 100644
--- a/internal/service/dataset/create_test.go
+++ b/internal/service/dataset/create_test.go
@@ -40,6 +40,8 @@ func testDatasetCreateService(t *testing.T) *DatasetService {
}
}
+func iptr(i int) *int { return &i }
+
func TestCreateDataset_NoComponentParams(t *testing.T) {
db := setupServiceTestDB(t)
pushServiceDB(t, db)
@@ -77,6 +79,8 @@ func TestCreateDataset_DefaultsParentChildConfig(t *testing.T) {
result, code, err := testDatasetCreateService(t).CreateDataset(t.Context(), &service.CreateDatasetRequest{
Name: "ds-default-parent-child",
+ ParserID: sptr("general"),
+ ParseType: iptr(1),
ParserConfig: map[string]interface{}{},
}, "tenant-1")
if err != nil || code != common.CodeSuccess {
@@ -113,21 +117,6 @@ func findChunkerNodeInTest(t *testing.T, config map[string]interface{}) map[stri
return nil
}
-func TestCreateDataset_BuiltinParserDoesNotRequireParseType(t *testing.T) {
- db := setupServiceTestDB(t)
- pushServiceDB(t, db)
- insertCreateDatasetTenant(t, "tenant-1")
-
- parserID := "qa"
- _, code, err := testDatasetCreateService(t).CreateDataset(t.Context(), &service.CreateDatasetRequest{
- Name: "ds-parser-only",
- ParserID: &parserID,
- }, "tenant-1")
- if err != nil || code != common.CodeSuccess {
- t.Fatalf("CreateDataset err=%v code=%d", err, code)
- }
-}
-
func TestCreateDataset_ComponentParamsPopulated(t *testing.T) {
db := setupServiceTestDB(t)
pushServiceDB(t, db)
@@ -234,20 +223,18 @@ func TestCreateDataset_PreservesChunkerComponentOverrides(t *testing.T) {
}
}
-func TestCreateDataset_ParseTypeBuiltinClearsPipelineID(t *testing.T) {
+func TestCreateDataset_ParseTypeBuiltinHasNoPipelineID(t *testing.T) {
db := setupServiceTestDB(t)
pushServiceDB(t, db)
insertCreateDatasetTenant(t, "tenant-1")
ctx := t.Context()
- pipelineID := "0123456789abcdef0123456789abcdef"
parseTypeBuiltin := 1
chunkMethod := "naive"
result, code, err := testDatasetCreateService(t).CreateDataset(ctx, &service.CreateDatasetRequest{
- Name: "ds-parse-builtin",
- ParserID: &chunkMethod,
- PipelineID: &pipelineID,
- ParseType: &parseTypeBuiltin,
+ Name: "ds-parse-builtin",
+ ParserID: &chunkMethod,
+ ParseType: &parseTypeBuiltin,
}, "tenant-1")
if err != nil {
t.Fatalf("CreateDataset failed: %v", err)
@@ -272,10 +259,8 @@ func TestCreateDataset_ParseTypePipelineIgnoresParserID(t *testing.T) {
pipelineID := "0123456789abcdef0123456789abcdef"
parseTypePipeline := 2
- chunkMethod := "naive"
result, code, err := testDatasetCreateService(t).CreateDataset(ctx, &service.CreateDatasetRequest{
Name: "ds-parse-pipeline",
- ParserID: &chunkMethod,
PipelineID: &pipelineID,
ParseType: &parseTypePipeline,
}, "tenant-1")
@@ -327,7 +312,11 @@ func TestCreateDataset_DedupesDuplicateName(t *testing.T) {
ctx := t.Context()
// Mirror Python's duplicate_name: the create appends (1) instead of failing.
- result, code, err := testDatasetCreateService(t).CreateDataset(ctx, &service.CreateDatasetRequest{Name: "Existing"}, "tenant-1")
+ result, code, err := testDatasetCreateService(t).CreateDataset(ctx, &service.CreateDatasetRequest{
+ Name: "Existing",
+ ParserID: sptr("general"),
+ ParseType: iptr(1),
+ }, "tenant-1")
if err != nil {
t.Fatalf("expected success, got %v", err)
}
@@ -363,6 +352,8 @@ func TestCreateDataset_RejectsInvalidEmbeddingModel(t *testing.T) {
_, code, err := testDatasetCreateService(t).CreateDataset(ctx, &service.CreateDatasetRequest{
Name: "ds-embd-" + tc.name,
+ ParserID: sptr("general"),
+ ParseType: iptr(1),
EmbeddingModel: &tc.embeddingModel,
}, "tenant-1")
if err == nil {
@@ -386,8 +377,10 @@ func TestCreateDataset_SetsExplicitLanguage(t *testing.T) {
language := " Chinese "
result, code, err := testDatasetCreateService(t).CreateDataset(ctx, &service.CreateDatasetRequest{
- Name: "ds-language",
- Language: &language,
+ Name: "ds-language",
+ Language: &language,
+ ParserID: sptr("general"),
+ ParseType: iptr(1),
}, "tenant-1")
if err != nil {
t.Fatalf("CreateDataset failed: %v", err)
@@ -408,7 +401,11 @@ func TestCreateDataset_OmittedLanguageKeepsDefault(t *testing.T) {
// An omitted language must stay unset on the insert so the column default
// applies, mirroring the Python service dropping a None language.
- result, code, err := testDatasetCreateService(t).CreateDataset(ctx, &service.CreateDatasetRequest{Name: "ds-no-language"}, "tenant-1")
+ result, code, err := testDatasetCreateService(t).CreateDataset(ctx, &service.CreateDatasetRequest{
+ Name: "ds-no-language",
+ ParserID: sptr("general"),
+ ParseType: iptr(1),
+ }, "tenant-1")
if err != nil {
t.Fatalf("CreateDataset failed: %v", err)
}
@@ -436,8 +433,10 @@ func TestCreateDataset_RejectsBlankLanguage(t *testing.T) {
insertCreateDatasetTenant(t, "tenant-1")
_, code, err := testDatasetCreateService(t).CreateDataset(t.Context(), &service.CreateDatasetRequest{
- Name: "ds-blank-language",
- Language: &language,
+ Name: "ds-blank-language",
+ Language: &language,
+ ParserID: sptr("general"),
+ ParseType: iptr(1),
}, "tenant-1")
if err == nil {
t.Fatal("expected language validation error")
@@ -464,8 +463,10 @@ func TestCreateDataset_LanguageLimitCountsCharacters(t *testing.T) {
ctx := t.Context()
result, code, err := testDatasetCreateService(t).CreateDataset(ctx, &service.CreateDatasetRequest{
- Name: "ds-language-at-limit",
- Language: &atLimit,
+ Name: "ds-language-at-limit",
+ Language: &atLimit,
+ ParserID: sptr("general"),
+ ParseType: iptr(1),
}, "tenant-1")
if err != nil {
t.Fatalf("CreateDataset failed for a %d-character language: %v", datasetLanguageLimit, err)
@@ -478,8 +479,10 @@ func TestCreateDataset_LanguageLimitCountsCharacters(t *testing.T) {
}
_, code, err = testDatasetCreateService(t).CreateDataset(ctx, &service.CreateDatasetRequest{
- Name: "ds-language-over-limit",
- Language: &overLimit,
+ Name: "ds-language-over-limit",
+ Language: &overLimit,
+ ParserID: sptr("general"),
+ ParseType: iptr(1),
}, "tenant-1")
if err == nil {
t.Fatal("expected language length validation error")
diff --git a/internal/service/dataset/crud.go b/internal/service/dataset/crud.go
index 60551f9e00..35da7433f7 100644
--- a/internal/service/dataset/crud.go
+++ b/internal/service/dataset/crud.go
@@ -37,19 +37,23 @@ func (d *DatasetService) CreateDataset(ctx context.Context, req *service.CreateD
return nil, common.CodeDataError, errors.New("tenant not found")
}
- // A built-in parser_id is valid without parse_type. parse_type is only
- // required when selecting a pipeline or explicitly supplied.
- if req.PipelineID != nil || req.ParseType != nil {
- isBuiltin, isPipeline, err := service.ValidateParseTypeMode(req.ParseType, req.ParserID, req.PipelineID)
- if err != nil {
- return nil, common.CodeDataError, err
- }
- if isBuiltin && req.PipelineID != nil {
- req.PipelineID = nil
- }
- if isPipeline && req.ParserID != nil {
- req.ParserID = nil
- }
+ // parse_type is required on dataset creation: it explicitly selects BuiltIn
+ // (1) or Pipeline (2) mode. This replaces the previous silent default to
+ // BuiltIn when the field was omitted. FromRequest validates the
+ // parse_type/parser_id/pipeline_id triple; Resolve enforces that a selection
+ // is actually present (current is nil on create).
+ sel, err := service.FromRequest(req.ParseType, req.ParserID, req.PipelineID)
+ if err != nil {
+ return nil, common.CodeDataError, err
+ }
+ if _, err = service.Resolve(nil, sel); err != nil {
+ return nil, common.CodeDataError, err
+ }
+ if sel.IsBuiltIn() && req.PipelineID != nil {
+ req.PipelineID = nil
+ }
+ if sel.IsPipeline() && req.ParserID != nil {
+ req.ParserID = nil
}
parserID := string(entity.ParserTypeGeneral)
diff --git a/internal/service/dataset/parse_type_required_test.go b/internal/service/dataset/parse_type_required_test.go
new file mode 100644
index 0000000000..d64b689ab4
--- /dev/null
+++ b/internal/service/dataset/parse_type_required_test.go
@@ -0,0 +1,119 @@
+package dataset
+
+import (
+ "testing"
+
+ "ragflow/internal/common"
+ "ragflow/internal/service"
+)
+
+// parse_type is now a required field on dataset creation. These tests lock in
+// that contract: a create request must explicitly select BuiltIn (1) or
+// Pipeline (2) mode, and must supply the matching identifier.
+
+func TestCreateDataset_RequiresParseType(t *testing.T) {
+ db := setupServiceTestDB(t)
+ pushServiceDB(t, db)
+ insertCreateDatasetTenant(t, "tenant-1")
+
+ // No parse_type, no parser_id, no pipeline_id. The previous code silently
+ // defaulted to BuiltIn; now this must be rejected.
+ _, code, err := testDatasetCreateService(t).CreateDataset(t.Context(), &service.CreateDatasetRequest{
+ Name: "ds-no-parse-type",
+ }, "tenant-1")
+ if err == nil {
+ t.Fatal("expected parse_type required error")
+ }
+ if code != common.CodeDataError {
+ t.Fatalf("expected data error code, got %d", code)
+ }
+ if err.Error() != "parse_type is required" {
+ t.Fatalf("unexpected error: got %q, want %q", err.Error(), "parse_type is required")
+ }
+}
+
+func TestCreateDataset_BuiltinRequiresParserID(t *testing.T) {
+ db := setupServiceTestDB(t)
+ pushServiceDB(t, db)
+ insertCreateDatasetTenant(t, "tenant-1")
+
+ parseType := 1
+ _, code, err := testDatasetCreateService(t).CreateDataset(t.Context(), &service.CreateDatasetRequest{
+ Name: "ds-builtin-no-parser",
+ ParseType: &parseType,
+ }, "tenant-1")
+ if err == nil {
+ t.Fatal("expected parser_id required error for BuiltIn mode")
+ }
+ if code != common.CodeDataError {
+ t.Fatalf("expected data error code, got %d", code)
+ }
+ if err.Error() != "parser_id is required when parse_type is BuiltIn" {
+ t.Fatalf("unexpected error: got %q", err.Error())
+ }
+}
+
+func TestCreateDataset_PipelineRequiresPipelineID(t *testing.T) {
+ db := setupServiceTestDB(t)
+ pushServiceDB(t, db)
+ insertCreateDatasetTenant(t, "tenant-1")
+
+ parseType := 2
+ _, code, err := testDatasetCreateService(t).CreateDataset(t.Context(), &service.CreateDatasetRequest{
+ Name: "ds-pipeline-no-id",
+ ParseType: &parseType,
+ }, "tenant-1")
+ if err == nil {
+ t.Fatal("expected pipeline_id required error for Pipeline mode")
+ }
+ if code != common.CodeDataError {
+ t.Fatalf("expected data error code, got %d", code)
+ }
+ if err.Error() != "pipeline_id is required when parse_type is Pipeline" {
+ t.Fatalf("unexpected error: got %q", err.Error())
+ }
+}
+
+func TestCreateDataset_RejectsInvalidParseType(t *testing.T) {
+ db := setupServiceTestDB(t)
+ pushServiceDB(t, db)
+ insertCreateDatasetTenant(t, "tenant-1")
+
+ parseType := 3
+ _, code, err := testDatasetCreateService(t).CreateDataset(t.Context(), &service.CreateDatasetRequest{
+ Name: "ds-bad-parse-type",
+ ParseType: &parseType,
+ }, "tenant-1")
+ if err == nil {
+ t.Fatal("expected invalid parse_type error")
+ }
+ if code != common.CodeDataError {
+ t.Fatalf("expected data error code, got %d", code)
+ }
+ if err.Error() != "invalid parse_type: 3 (must be 1 or 2)" {
+ t.Fatalf("unexpected error: got %q", err.Error())
+ }
+}
+
+func TestCreateDataset_BuiltinSucceedsWithParseType(t *testing.T) {
+ db := setupServiceTestDB(t)
+ pushServiceDB(t, db)
+ insertCreateDatasetTenant(t, "tenant-1")
+
+ parseType := 1
+ parserID := "general"
+ result, code, err := testDatasetCreateService(t).CreateDataset(t.Context(), &service.CreateDatasetRequest{
+ Name: "ds-builtin-ok",
+ ParseType: &parseType,
+ ParserID: &parserID,
+ }, "tenant-1")
+ if err != nil {
+ t.Fatalf("CreateDataset failed: %v", err)
+ }
+ if code != common.CodeSuccess {
+ t.Fatalf("expected success code, got %d", code)
+ }
+ if result["parser_id"] != "general" {
+ t.Fatalf("expected parser_id general, got %#v", result["parser_id"])
+ }
+}
diff --git a/internal/service/dataset/update.go b/internal/service/dataset/update.go
index 2181dca98c..99b330171a 100644
--- a/internal/service/dataset/update.go
+++ b/internal/service/dataset/update.go
@@ -102,19 +102,19 @@ func (d *DatasetService) UpdateDataset(ctx context.Context, datasetID, tenantID
simpleUpdates["permission"] = permission
}
- if req.ParseType == nil && req.ParserID != nil && req.PipelineID != nil {
- return nil, common.CodeDataError, errors.New("mutually exclusive")
+ // Validate the parse_type/parser_id/pipeline_id triple. FromRequest rejects
+ // any partial or contradictory combination (e.g. an id without parse_type,
+ // or both ids). A fully-absent block is allowed on update and means "keep
+ // current" — handled below via Resolve.
+ sel, modeErr := service.FromRequest(req.ParseType, req.ParserID, req.PipelineID)
+ if modeErr != nil {
+ return nil, common.CodeDataError, modeErr
}
-
- if req.PipelineID != nil || req.ParseType != nil {
- isBuiltin, isPipeline, modeErr := service.ValidateParseTypeMode(req.ParseType, req.ParserID, req.PipelineID)
- if modeErr != nil {
- return nil, common.CodeDataError, modeErr
- }
- if isBuiltin && req.PipelineID != nil {
+ if sel != nil {
+ if sel.IsBuiltIn() && req.PipelineID != nil {
req.PipelineID = nil
}
- if isPipeline && req.ParserID != nil {
+ if sel.IsPipeline() && req.ParserID != nil {
req.ParserID = nil
}
}
@@ -238,13 +238,17 @@ func (d *DatasetService) UpdateDataset(ctx context.Context, datasetID, tenantID
}
if req.ParserConfig != nil && len(req.ParserConfig) > 0 {
- // Resolve effective mode/IDs once via the shared helper. parse_type
- // is authoritative; the per-mode req IDs were already cleaned above,
- // but ResolveParseMode does not rely on that — it ignores the
- // non-applicable ID for the selected mode.
- isPipeline, effParserID, effPipelineID := service.ResolveParseMode(
- req.ParseType, req.ParserID, req.PipelineID,
- service.ParseModeState{ParserID: lockedKB.ParserID, PipelineID: lockedKB.PipelineID})
+ // Resolve the effective mode/IDs once. sel is the request selection
+ // (nil when the whole selection block was omitted); current is the
+ // persisted selection. Resolve applies PATCH semantics: an omitted
+ // block keeps the current mode so only parser_config changes still
+ // load the correct DSL.
+ current := service.CurrentSelection(lockedKB.ParserID, lockedKB.PipelineID)
+ eff, resolveErr := service.Resolve(current, sel)
+ if resolveErr != nil {
+ return resolveErr
+ }
+ isPipeline, effParserID, effPipelineID := eff.Effective()
dslJSON, dslErr := service.LoadPipelineDSL(ctx, isPipeline, effParserID, effPipelineID)
if dslErr != nil {
common.Warn("failed to load pipeline DSL for building parser_config",
diff --git a/internal/service/dataset/update_test.go b/internal/service/dataset/update_test.go
index 7b9b6d0b0a..8bd5e11a2d 100644
--- a/internal/service/dataset/update_test.go
+++ b/internal/service/dataset/update_test.go
@@ -193,13 +193,13 @@ func TestUpdateDataset_RejectsSimultaneousParserIDAndPipelineID(t *testing.T) {
PipelineID: &pipelineID,
})
if err == nil {
- t.Fatal("expected mutual-exclusivity error when both parser_id and pipeline_id are set")
+ t.Fatal("expected error when both parser_id and pipeline_id are set without parse_type")
}
if code != common.CodeDataError {
t.Fatalf("expected data error code, got %d", code)
}
- if !strings.Contains(err.Error(), "mutually exclusive") {
- t.Fatalf("expected error to mention 'mutually exclusive', got: %v", err)
+ if err.Error() != "parse_type is required" {
+ t.Fatalf("expected 'parse_type is required', got: %v", err)
}
}
@@ -211,14 +211,12 @@ func TestUpdateDataset_ParseTypeBuiltinClearsPipelineID(t *testing.T) {
datasetUpdateCanvasDSL("Parser:HipSignsRhyme", "chunk_token_num"))
chunkMethod := "book"
- pipelineID := "ABCDEF0123456789ABCDEF0123456789"
parseType := 1
ctx := t.Context()
result, code, err := testDatasetUpdateService(t).UpdateDataset(ctx, "kb-1", "tenant-1", service.UpdateDatasetRequest{
- ParserID: &chunkMethod,
- PipelineID: &pipelineID,
- ParseType: &parseType,
+ ParserID: &chunkMethod,
+ ParseType: &parseType,
})
if err != nil {
t.Fatalf("UpdateDataset failed: %v", err)
@@ -226,7 +224,7 @@ func TestUpdateDataset_ParseTypeBuiltinClearsPipelineID(t *testing.T) {
if code != common.CodeSuccess {
t.Fatalf("expected success code, got %d", code)
}
- // parse_type=1 clears pipeline_id → only parser_id should be set.
+ // parse_type=1 selects builtin mode → only parser_id should be set.
if result["parser_id"] != chunkMethod {
t.Fatalf("expected parser_id %q, got %#v", chunkMethod, result["parser_id"])
}
@@ -235,40 +233,32 @@ func TestUpdateDataset_ParseTypeBuiltinClearsPipelineID(t *testing.T) {
}
}
-func TestUpdateDataset_ParseTypePipelineIgnoresParserID(t *testing.T) {
+// TestUpdateDataset_ParseTypePipelineRejectsParserID locks in the new explicit
+// contract: parse_type=2 (Pipeline) must not carry a parser_id. The previous
+// lenient behavior silently ignored the contradictory id; now it is rejected so
+// a malformed request can never pick the wrong mode.
+func TestUpdateDataset_ParseTypePipelineRejectsParserID(t *testing.T) {
db := setupDatasetUpdateTestDB(t)
pushServiceDB(t, db)
insertDatasetUpdateKB(t, "kb-1", "tenant-1", "Original")
- seedDatasetUpdateCanvas(t, "abcdef0123456789abcdef0123456789", "tenant-1",
- datasetUpdateCanvasDSL("Parser:CustomP", "chunk_token_num"))
chunkMethod := "book"
pipelineID := "ABCDEF0123456789ABCDEF0123456789"
parseType := 2
- ctx := t.Context()
- result, code, err := testDatasetUpdateService(t).UpdateDataset(ctx, "kb-1", "tenant-1", service.UpdateDatasetRequest{
+ _, code, err := testDatasetUpdateService(t).UpdateDataset(t.Context(), "kb-1", "tenant-1", service.UpdateDatasetRequest{
ParserID: &chunkMethod,
PipelineID: &pipelineID,
ParseType: &parseType,
})
- if err != nil {
- t.Fatalf("UpdateDataset failed: %v", err)
- }
- if code != common.CodeSuccess {
- t.Fatalf("expected success code, got %d", code)
- }
- // parse_type=2 ignores parser_id → pipeline_id should be set;
- // parser_id should keep the original value.
- if result["pipeline_id"] != strings.ToLower(pipelineID) {
- t.Fatalf("expected pipeline_id %q, got %#v", strings.ToLower(pipelineID), result["pipeline_id"])
+ if err == nil {
+ t.Fatal("expected error rejecting parser_id in Pipeline mode")
}
- persisted, err := dao.NewKnowledgebaseDAO().GetByID(ctx, db, "kb-1")
- if err != nil {
- t.Fatalf("get updated kb: %v", err)
+ if code != common.CodeDataError {
+ t.Fatalf("expected data error code, got %d", code)
}
- if _, ok := persisted.ParserConfig["Parser:CustomP"].(map[string]interface{}); !ok {
- t.Fatalf("expected pipeline defaults in parser_config, got %#v", persisted.ParserConfig)
+ if err.Error() != "parser_id must not be set when parse_type is Pipeline" {
+ t.Fatalf("unexpected error: %v", err)
}
}
@@ -343,9 +333,8 @@ func TestUpdateDataset_ParseTypePipelineCleansConfigAgainstCanvas(t *testing.T)
seedDatasetUpdateCanvas(t, "abcdef0123456789abcdef0123456789", "tenant-1",
datasetUpdateCanvasDSL("Parser:CustomP", "chunk_token_num"))
- // Dirty parser_id that the builtin branch would otherwise use to load a
- // builtin DSL. parse_type=2 must ignore it.
- chunkMethod := "book"
+ // parse_type=2 must clean the config against the canvas DSL. No parser_id is
+ // sent in pipeline mode (the new contract forbids a contradictory id).
pipelineID := "abcdef0123456789abcdef0123456789"
parseType := 2
override := map[string]interface{}{
@@ -354,7 +343,6 @@ func TestUpdateDataset_ParseTypePipelineCleansConfigAgainstCanvas(t *testing.T)
ctx := t.Context()
_, code, err := testDatasetUpdateService(t).UpdateDataset(ctx, "kb-1", "tenant-1", service.UpdateDatasetRequest{
- ParserID: &chunkMethod,
PipelineID: &pipelineID,
ParseType: &parseType,
ParserConfig: override,
diff --git a/internal/service/document/document_dataset_update.go b/internal/service/document/document_dataset_update.go
index 830c1b5300..cabe485207 100644
--- a/internal/service/document/document_dataset_update.go
+++ b/internal/service/document/document_dataset_update.go
@@ -141,13 +141,19 @@ func (s *DocumentService) UpdateDatasetDocument(ctx context.Context, userID, dat
}
}
- // Resolve the effective parse mode once: parse_type is authoritative when
- // present, otherwise inherit the dataset's current mode. Both the
+ // Resolve the effective parse mode once via the shared selection value
+ // object. sel is the request selection (nil when the whole selection block
+ // was omitted); current is the dataset's persisted selection. Resolve applies
+ // PATCH semantics: an omitted block inherits the current mode. Both the
// parser_config cleaning and the reparse targeting derive from this single
- // resolution so they can never disagree. (See service.ResolveParseMode.)
- isPipeline, effParserID, effPipelineID := service.ResolveParseMode(
- req.ParseType, req.ParserID, req.PipelineID,
- service.ParseModeState{ParserID: kb.ParserID, PipelineID: kb.PipelineID})
+ // resolution so they can never disagree.
+ sel, selErr := service.FromRequest(req.ParseType, req.ParserID, req.PipelineID)
+ if selErr != nil {
+ return nil, common.CodeDataError, selErr
+ }
+ current := service.CurrentSelection(kb.ParserID, kb.PipelineID)
+ eff, _ := service.Resolve(current, sel)
+ isPipeline, effParserID, effPipelineID := eff.Effective()
if present["parser_config"] && req.ParserConfig != nil {
// Normalize "pages" ranges before persistence. Invalid ranges are
@@ -322,13 +328,13 @@ func (s *DocumentService) validateDatasetDocumentUpdate(ctx context.Context, dat
}
if present["parse_type"] || present["parser_id"] || present["pipeline_id"] {
- isBuiltin, _, err := service.ValidateParseTypeMode(req.ParseType, req.ParserID, req.PipelineID)
+ sel, err := service.FromRequest(req.ParseType, req.ParserID, req.PipelineID)
if err != nil {
return common.CodeDataError, err
}
// The parser_id type constraint (visual/presentation) only applies in
// builtin mode — in pipeline mode parser_id is not applicable.
- if isBuiltin && present["parser_id"] && req.ParserID != nil {
+ if sel != nil && sel.IsBuiltIn() && present["parser_id"] && req.ParserID != nil {
parserID := strings.TrimSpace(*req.ParserID)
if (doc.Type == "visual" && parserID != "picture") || (isPresentationFile(doc.Name) && parserID != "presentation") {
return common.CodeDataError, errors.New("not supported yet")
diff --git a/internal/service/document/document_test.go b/internal/service/document/document_test.go
index 9e4a0e0442..0895aad093 100644
--- a/internal/service/document/document_test.go
+++ b/internal/service/document/document_test.go
@@ -3372,15 +3372,13 @@ func TestUpdateDatasetDocumentPipelineIDTakesPrecedenceOverParserID(t *testing.T
insertNamedTestDoc(t, "doc-1", "kb-1", "doc.txt", 10, 5)
pipelineID := "1234567890abcdef1234567890abcdef"
- chunkMethod := "manual"
parseType := 2
svc := testDocumentService(t)
ctx := t.Context()
resp, code, err := svc.UpdateDatasetDocument(ctx, "tenant-1", "kb-1", "doc-1", &UpdateDatasetDocumentRequest{
PipelineID: &pipelineID,
- ParserID: &chunkMethod,
ParseType: &parseType,
- }, map[string]bool{"pipeline_id": true, "parser_id": true, "parse_type": true})
+ }, map[string]bool{"pipeline_id": true, "parse_type": true})
if err != nil {
t.Fatalf("UpdateDatasetDocument failed: code=%v err=%v", code, err)
}
@@ -3462,50 +3460,34 @@ func TestUpdateDatasetDocumentParseTypePipeline(t *testing.T) {
}
}
-// TestUpdateDatasetDocumentParseTypePipelineIgnoresDirtyParserID reproduces
-// the comment-3 bug: parse_type=2 (pipeline) with a dirty req.ParserID must
-// still resolve to pipeline mode so parser_config is cleaned against the
-// canvas DSL (fallback when the canvas is absent), not the builtin DSL.
-//
-// With the bug, req.ParserID != nil flipped isCanvas=false inside the
-// parser_config block, so the config was rebuilt against the builtin "manual"
-// DSL and unknown fields were dropped. After the fix, the canvas load fails
-// (no such pipeline in the test DB) and the original config is persisted as-is.
-func TestUpdateDatasetDocumentParseTypePipelineIgnoresDirtyParserID(t *testing.T) {
+// TestUpdateDatasetDocumentParseTypePipelineRejectsParserID locks in the new
+// explicit contract: parse_type=2 (Pipeline) must not carry a parser_id. The
+// previous lenient behavior silently ignored the contradictory id; now it is
+// rejected so a malformed request can never pick the wrong mode.
+func TestUpdateDatasetDocumentParseTypePipelineRejectsParserID(t *testing.T) {
db := setupServiceTestDB(t)
pushServiceDB(t, db)
insertTestKB(t, "kb-1", "tenant-1", 1, 10, 5)
insertNamedTestDoc(t, "doc-1", "kb-1", "doc.txt", 10, 5)
parseType := 2
- // Dirty parser_id that the builtin branch would otherwise use to load a
- // builtin DSL and strip unknown fields.
parserID := "manual"
pipelineID := "1234567890abcdef1234567890abcdef"
svc := testDocumentService(t)
ctx := t.Context()
- resp, code, err := svc.UpdateDatasetDocument(ctx, "tenant-1", "kb-1", "doc-1", &UpdateDatasetDocumentRequest{
+ _, code, err := svc.UpdateDatasetDocument(ctx, "tenant-1", "kb-1", "doc-1", &UpdateDatasetDocumentRequest{
ParseType: &parseType,
ParserID: &parserID,
PipelineID: &pipelineID,
- ParserConfig: map[string]any{
- "nonexistent_field": "value",
- },
- }, map[string]bool{"parser_id": true, "pipeline_id": true, "parse_type": true, "parser_config": true})
- if err != nil {
- t.Fatalf("UpdateDatasetDocument failed: code=%v err=%v", code, err)
- }
- if resp.PipelineID == nil || *resp.PipelineID != pipelineID {
- t.Fatalf("pipeline_id = %v, want %q", resp.PipelineID, pipelineID)
+ }, map[string]bool{"parser_id": true, "pipeline_id": true, "parse_type": true})
+ if err == nil {
+ t.Fatal("expected error rejecting parser_id in Pipeline mode")
}
- if resp.ParserID != "naive" {
- t.Fatalf("parser_id = %q, want original naive (parser_id must not apply in pipeline mode)", resp.ParserID)
+ if code != common.CodeDataError {
+ t.Fatalf("code = %v, want %v", code, common.CodeDataError)
}
- // Pipeline mode with an absent canvas must fall back to persisting the
- // original config verbatim. If the builtin path ran instead, the unknown
- // field would have been stripped during DSL cleaning.
- if v, ok := resp.ParserConfig["nonexistent_field"]; !ok || v != "value" {
- t.Fatalf("parser_config = %v, want nonexistent_field=value preserved (canvas fallback)", resp.ParserConfig)
+ if err.Error() != "parser_id must not be set when parse_type is Pipeline" {
+ t.Fatalf("err = %q", err.Error())
}
}
diff --git a/internal/service/parser_mode.go b/internal/service/parser_mode.go
index 7836c2911d..bf18bb16e2 100644
--- a/internal/service/parser_mode.go
+++ b/internal/service/parser_mode.go
@@ -6,84 +6,117 @@ import (
"strings"
)
-// ValidateParseTypeMode validates parse_type and ensures the corresponding
-// identifier field is present. Returns (isBuiltin, isPipeline, error).
-// - parse_type must be 1 (BuiltIn) or 2 (Pipeline); nil is an error.
-// - BuiltIn mode requires parserID to be present and non-empty.
-// - Pipeline mode requires pipelineID to be present and non-empty.
-func ValidateParseTypeMode(parseType *int, parserID, pipelineID *string) (isBuiltin bool, isPipeline bool, err error) {
+// ParseMode identifies which parser backend a dataset or document uses.
+type ParseMode int
+
+const (
+ // ParseModeBuiltIn selects a builtin parser template (parser_id).
+ ParseModeBuiltIn ParseMode = 1
+ // ParseModePipeline selects a user canvas pipeline (pipeline_id).
+ ParseModePipeline ParseMode = 2
+)
+
+// ParserSelection is the canonical, unambiguous choice of parser backend.
+// Exactly one of (Mode == BuiltIn with a non-empty ParserID) or
+// (Mode == Pipeline with a non-empty PipelineID) holds. Construct it only via
+// FromRequest (from a request) or CurrentSelection (from persisted columns);
+// never build it directly. Centralizing construction here removes the old
+// three-field ambiguity (parse_type / parser_id / pipeline_id) and the nil
+// branch that inferred the mode from whichever ID happened to be present.
+type ParserSelection struct {
+ Mode ParseMode
+ ParserID string
+ PipelineID string
+}
+
+// IsBuiltIn reports whether the selection targets a builtin parser.
+func (s *ParserSelection) IsBuiltIn() bool {
+ return s != nil && s.Mode == ParseModeBuiltIn
+}
+
+// IsPipeline reports whether the selection targets a canvas pipeline.
+func (s *ParserSelection) IsPipeline() bool {
+ return s != nil && s.Mode == ParseModePipeline
+}
+
+// Effective returns the (isPipeline, parserID, pipelineID) representation used
+// for storage and DSL loading. Exactly one of parserID/pipelineID is non-empty:
+// for BuiltIn the pipeline_id is nil, for Pipeline the parser_id is the stored
+// builtin id (ignored by the canvas DSL loader) and pipeline_id carries the
+// canvas id.
+func (s *ParserSelection) Effective() (isPipeline bool, parserID string, pipelineID *string) {
+ if s == nil {
+ return false, "", nil
+ }
+ if s.IsPipeline() {
+ pid := s.PipelineID
+ return true, s.ParserID, &pid
+ }
+ return false, s.ParserID, nil
+}
+
+func isBlankID(p *string) bool {
+ return p == nil || strings.TrimSpace(*p) == ""
+}
+
+// FromRequest validates the raw request fields and returns the corresponding
+// ParserSelection. It returns (nil, nil) when all three fields are absent —
+// the PATCH signal that the whole selection block is omitted and the current
+// selection must be kept. Any other partial presence is rejected so a malformed
+// request can never silently pick the wrong mode:
+// - no parse_type while an id is present -> "parse_type is required"
+// - an id contradictory to parse_type -> explicit mismatch error
+// - an unknown parse_type value -> "invalid parse_type"
+func FromRequest(parseType *int, parserID, pipelineID *string) (*ParserSelection, error) {
+ if parseType == nil && isBlankID(parserID) && isBlankID(pipelineID) {
+ return nil, nil
+ }
if parseType == nil {
- return false, false, errors.New("parse_type is required")
+ return nil, errors.New("parse_type is required")
}
switch *parseType {
- case 1:
- if parserID == nil || strings.TrimSpace(*parserID) == "" {
- return false, false, errors.New("parser_id is required when parse_type is BuiltIn")
+ case 1: // BuiltIn
+ if !isBlankID(pipelineID) {
+ return nil, errors.New("pipeline_id must not be set when parse_type is BuiltIn")
+ }
+ if isBlankID(parserID) {
+ return nil, errors.New("parser_id is required when parse_type is BuiltIn")
}
- return true, false, nil
- case 2:
- if pipelineID == nil || strings.TrimSpace(*pipelineID) == "" {
- return false, false, errors.New("pipeline_id is required when parse_type is Pipeline")
+ return &ParserSelection{Mode: ParseModeBuiltIn, ParserID: strings.TrimSpace(*parserID)}, nil
+ case 2: // Pipeline
+ if !isBlankID(parserID) {
+ return nil, errors.New("parser_id must not be set when parse_type is Pipeline")
}
- return false, true, nil
+ if isBlankID(pipelineID) {
+ return nil, errors.New("pipeline_id is required when parse_type is Pipeline")
+ }
+ return &ParserSelection{Mode: ParseModePipeline, PipelineID: strings.TrimSpace(*pipelineID)}, nil
default:
- return false, false, fmt.Errorf("invalid parse_type: %d (must be 1 or 2)", *parseType)
+ return nil, fmt.Errorf("invalid parse_type: %d (must be 1 or 2)", *parseType)
}
}
-// ParseModeState carries the persisted IDs that ResolveParseMode falls back to
-// when the request does not switch modes.
-type ParseModeState struct {
- ParserID string
- PipelineID *string
+// CurrentSelection builds the ParserSelection currently persisted on a
+// dataset/document from its parser_id / pipeline_id columns.
+func CurrentSelection(parserID string, pipelineID *string) *ParserSelection {
+ if pipelineID != nil && strings.TrimSpace(*pipelineID) != "" {
+ return &ParserSelection{Mode: ParseModePipeline, ParserID: parserID, PipelineID: strings.TrimSpace(*pipelineID)}
+ }
+ return &ParserSelection{Mode: ParseModeBuiltIn, ParserID: parserID}
}
-// ResolveParseMode returns the effective (isPipeline, parserID, pipelineID)
-// after applying an update. It is the single source of truth for "which DSL
-// should parser_config be cleaned against" and "which mode should reparse
-// target", shared by the dataset and document update paths.
-//
-// parseType is authoritative when present:
-// - 1 (BuiltIn): effParserID = reqParserID (or current); effPipelineID = nil
-// so any prior canvas is cleared. reqPipelineID is ignored.
-// - 2 (Pipeline): effPipelineID = reqPipelineID (or current); effParserID =
-// current.ParserID (parser_id is not applicable in pipeline mode).
-// reqParserID is ignored.
-//
-// When parseType is nil (no mode switch, e.g. only parser_config changed),
-// inherit current mode and apply any incremental ID updates from the request;
-// isPipeline is derived from whether effPipelineID is non-empty.
-func ResolveParseMode(parseType *int, reqParserID, reqPipelineID *string,
- current ParseModeState) (isPipeline bool, effParserID string, effPipelineID *string) {
- if parseType != nil {
- switch *parseType {
- case 1: // BuiltIn
- effParserID = current.ParserID
- if reqParserID != nil {
- if p := strings.TrimSpace(*reqParserID); p != "" {
- effParserID = p
- }
- }
- return false, effParserID, nil
- case 2: // Pipeline
- effPipelineID = current.PipelineID
- if reqPipelineID != nil {
- effPipelineID = reqPipelineID
- }
- return true, current.ParserID, effPipelineID
+// Resolve combines the current selection with a request selection.
+// - Creation (current == nil): the request selection is mandatory, so a nil
+// sel is an error — a dataset/document must explicitly pick a mode.
+// - Update (current != nil): a nil sel means the whole selection block was
+// omitted and the current selection is kept (PATCH semantics); a non-nil
+// sel overrides it (mode switch or same-mode id change).
+func Resolve(current, sel *ParserSelection) (*ParserSelection, error) {
+ if sel == nil {
+ if current == nil {
+ return nil, errors.New("parse_type is required")
}
+ return current, nil
}
- // No mode switch — inherit current state, apply incremental ID updates.
- effParserID = current.ParserID
- if reqParserID != nil {
- if p := strings.TrimSpace(*reqParserID); p != "" {
- effParserID = p
- }
- }
- effPipelineID = current.PipelineID
- if reqPipelineID != nil {
- effPipelineID = reqPipelineID
- }
- isPipeline = effPipelineID != nil && strings.TrimSpace(*effPipelineID) != ""
- return isPipeline, effParserID, effPipelineID
+ return sel, nil
}
diff --git a/internal/service/parser_mode_test.go b/internal/service/parser_mode_test.go
index c3ee76bea1..e5db3ce5cf 100644
--- a/internal/service/parser_mode_test.go
+++ b/internal/service/parser_mode_test.go
@@ -4,205 +4,304 @@ import (
"testing"
)
-func TestValidateParseTypeMode_Nil(t *testing.T) {
- _, _, err := ValidateParseTypeMode(nil, nil, nil)
- if err == nil || err.Error() != "parse_type is required" {
+func pi(v int) *int { return &v }
+func ps(v string) *string { return &v }
+
+// All fields absent -> selection block omitted, no error, nil selection.
+func TestFromRequest_AllAbsent(t *testing.T) {
+ sel, err := FromRequest(nil, nil, nil)
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if sel != nil {
+ t.Fatalf("expected nil selection, got %#v", sel)
+ }
+}
+
+// Whitespace-only ids with no parse_type are treated as absent.
+func TestFromRequest_BlankIDsNoType(t *testing.T) {
+ sel, err := FromRequest(nil, ps(" "), ps("\t"))
+ if err != nil {
t.Fatalf("unexpected error: %v", err)
}
+ if sel != nil {
+ t.Fatalf("expected nil selection, got %#v", sel)
+ }
+}
+
+// An id without parse_type must be rejected (explicit discriminator required).
+func TestFromRequest_ParserIDWithoutType(t *testing.T) {
+ sel, err := FromRequest(nil, ps("general"), nil)
+ if err == nil || err.Error() != "parse_type is required" {
+ t.Fatalf("expected 'parse_type is required', got %v", err)
+ }
+ if sel != nil {
+ t.Fatalf("expected nil selection, got %#v", sel)
+ }
+}
+
+func TestFromRequest_PipelineIDWithoutType(t *testing.T) {
+ sel, err := FromRequest(nil, nil, ps("canvas-1"))
+ if err == nil || err.Error() != "parse_type is required" {
+ t.Fatalf("expected 'parse_type is required', got %v", err)
+ }
+ if sel != nil {
+ t.Fatalf("expected nil selection, got %#v", sel)
+ }
+}
+
+// Both ids without parse_type must be rejected.
+func TestFromRequest_BothIDsWithoutType(t *testing.T) {
+ sel, err := FromRequest(nil, ps("general"), ps("canvas-1"))
+ if err == nil || err.Error() != "parse_type is required" {
+ t.Fatalf("expected 'parse_type is required', got %v", err)
+ }
+ if sel != nil {
+ t.Fatalf("expected nil selection, got %#v", sel)
+ }
}
-func TestValidateParseTypeMode_InvalidZero(t *testing.T) {
- v := 0
- _, _, err := ValidateParseTypeMode(&v, nil, nil)
+func TestFromRequest_InvalidZero(t *testing.T) {
+ sel, err := FromRequest(pi(0), nil, nil)
if err == nil || err.Error() != "invalid parse_type: 0 (must be 1 or 2)" {
t.Fatalf("unexpected error: %v", err)
}
+ if sel != nil {
+ t.Fatalf("expected nil selection, got %#v", sel)
+ }
}
-func TestValidateParseTypeMode_InvalidThree(t *testing.T) {
- v := 3
- _, _, err := ValidateParseTypeMode(&v, nil, nil)
+func TestFromRequest_InvalidThree(t *testing.T) {
+ sel, err := FromRequest(pi(3), nil, nil)
if err == nil || err.Error() != "invalid parse_type: 3 (must be 1 or 2)" {
t.Fatalf("unexpected error: %v", err)
}
+ if sel != nil {
+ t.Fatalf("expected nil selection, got %#v", sel)
+ }
}
-func TestValidateParseTypeMode_BuiltinMissingParserID(t *testing.T) {
+func TestFromRequest_BuiltinMissingParserID(t *testing.T) {
t.Run("nil parserID", func(t *testing.T) {
- pt := 1
- _, _, err := ValidateParseTypeMode(&pt, nil, nil)
+ sel, err := FromRequest(pi(1), nil, nil)
if err == nil || err.Error() != "parser_id is required when parse_type is BuiltIn" {
t.Fatalf("unexpected error: %v", err)
}
+ if sel != nil {
+ t.Fatalf("expected nil selection, got %#v", sel)
+ }
})
t.Run("empty parserID", func(t *testing.T) {
- pt := 1
- empty := ""
- _, _, err := ValidateParseTypeMode(&pt, &empty, nil)
+ sel, err := FromRequest(pi(1), ps(""), nil)
if err == nil || err.Error() != "parser_id is required when parse_type is BuiltIn" {
t.Fatalf("unexpected error: %v", err)
}
+ if sel != nil {
+ t.Fatalf("expected nil selection, got %#v", sel)
+ }
})
t.Run("whitespace parserID", func(t *testing.T) {
- pt := 1
- ws := " "
- _, _, err := ValidateParseTypeMode(&pt, &ws, nil)
+ sel, err := FromRequest(pi(1), ps(" "), nil)
if err == nil || err.Error() != "parser_id is required when parse_type is BuiltIn" {
t.Fatalf("unexpected error: %v", err)
}
+ if sel != nil {
+ t.Fatalf("expected nil selection, got %#v", sel)
+ }
})
}
-func TestValidateParseTypeMode_BuiltinOK(t *testing.T) {
- pt := 1
- pid := "laws"
- builtin, pipeline, err := ValidateParseTypeMode(&pt, &pid, nil)
+// BuiltIn mode must not carry a pipeline_id (mode/id mismatch).
+func TestFromRequest_BuiltinWithPipelineID(t *testing.T) {
+ sel, err := FromRequest(pi(1), ps("general"), ps("canvas-1"))
+ if err == nil || err.Error() != "pipeline_id must not be set when parse_type is BuiltIn" {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if sel != nil {
+ t.Fatalf("expected nil selection, got %#v", sel)
+ }
+}
+
+func TestFromRequest_BuiltinOK(t *testing.T) {
+ sel, err := FromRequest(pi(1), ps(" laws "), nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
- if !builtin || pipeline {
- t.Fatalf("expected builtin=true pipeline=false, got builtin=%v pipeline=%v", builtin, pipeline)
+ if sel == nil || !sel.IsBuiltIn() || sel.IsPipeline() {
+ t.Fatalf("expected builtin selection, got %#v", sel)
+ }
+ if sel.ParserID != "laws" {
+ t.Fatalf("expected trimmed parser_id 'laws', got %q", sel.ParserID)
+ }
+ if sel.PipelineID != "" {
+ t.Fatalf("expected empty pipeline_id, got %q", sel.PipelineID)
}
}
-func TestValidateParseTypeMode_PipelineMissingPipelineID(t *testing.T) {
+func TestFromRequest_PipelineMissingPipelineID(t *testing.T) {
t.Run("nil pipelineID", func(t *testing.T) {
- pt := 2
- _, _, err := ValidateParseTypeMode(&pt, nil, nil)
+ sel, err := FromRequest(pi(2), nil, nil)
if err == nil || err.Error() != "pipeline_id is required when parse_type is Pipeline" {
t.Fatalf("unexpected error: %v", err)
}
+ if sel != nil {
+ t.Fatalf("expected nil selection, got %#v", sel)
+ }
})
t.Run("empty pipelineID", func(t *testing.T) {
- pt := 2
- empty := ""
- _, _, err := ValidateParseTypeMode(&pt, nil, &empty)
+ sel, err := FromRequest(pi(2), nil, ps(""))
if err == nil || err.Error() != "pipeline_id is required when parse_type is Pipeline" {
t.Fatalf("unexpected error: %v", err)
}
+ if sel != nil {
+ t.Fatalf("expected nil selection, got %#v", sel)
+ }
})
}
-func TestValidateParseTypeMode_PipelineOK(t *testing.T) {
- pt := 2
- pipe := "abc123"
- builtin, pipeline, err := ValidateParseTypeMode(&pt, nil, &pipe)
+// Pipeline mode must not carry a parser_id (mode/id mismatch).
+func TestFromRequest_PipelineWithParserID(t *testing.T) {
+ sel, err := FromRequest(pi(2), ps("general"), ps("canvas-1"))
+ if err == nil || err.Error() != "parser_id must not be set when parse_type is Pipeline" {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if sel != nil {
+ t.Fatalf("expected nil selection, got %#v", sel)
+ }
+}
+
+func TestFromRequest_PipelineOK(t *testing.T) {
+ sel, err := FromRequest(pi(2), nil, ps(" canvas-1 "))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
- if builtin || !pipeline {
- t.Fatalf("expected builtin=false pipeline=true, got builtin=%v pipeline=%v", builtin, pipeline)
+ if sel == nil || !sel.IsPipeline() || sel.IsBuiltIn() {
+ t.Fatalf("expected pipeline selection, got %#v", sel)
+ }
+ if sel.PipelineID != "canvas-1" {
+ t.Fatalf("expected trimmed pipeline_id 'canvas-1', got %q", sel.PipelineID)
+ }
+ if sel.ParserID != "" {
+ t.Fatalf("expected empty parser_id, got %q", sel.ParserID)
}
}
-func TestResolveParseMode_BuiltinIgnoresPipelineID(t *testing.T) {
- pt := 1
- parserID := "manual"
- pipelineID := "should-be-ignored"
- cur := ParseModeState{ParserID: "naive", PipelineID: strPtr("prior-canvas")}
- isPipeline, effParserID, effPipelineID := ResolveParseMode(&pt, &parserID, &pipelineID, cur)
+// Effective() for BuiltIn returns no pipeline_id.
+func TestParserSelection_EffectiveBuiltIn(t *testing.T) {
+ sel := &ParserSelection{Mode: ParseModeBuiltIn, ParserID: "general"}
+ isPipeline, parserID, pipelineID := sel.Effective()
if isPipeline {
- t.Fatalf("isPipeline = true, want false (builtin mode)")
+ t.Fatalf("isPipeline = true, want false")
}
- if effParserID != "manual" {
- t.Fatalf("effParserID = %q, want manual", effParserID)
+ if parserID != "general" {
+ t.Fatalf("parserID = %q, want general", parserID)
}
- if effPipelineID != nil {
- t.Fatalf("effPipelineID = %v, want nil (canvas cleared)", effPipelineID)
+ if pipelineID != nil {
+ t.Fatalf("pipelineID = %v, want nil", pipelineID)
}
}
-// TestResolveParseMode_PipelineIgnoresParserID reproduces the comment-3 bug
-// contract: parse_type=2 must ignore a dirty req.ParserID and keep isPipeline
-// true so parser_config is cleaned against the canvas DSL, not the builtin DSL.
-func TestResolveParseMode_PipelineIgnoresParserID(t *testing.T) {
- pt := 2
- parserID := "should-be-ignored"
- pipelineID := "1234567890abcdef1234567890abcdef"
- cur := ParseModeState{ParserID: "naive", PipelineID: nil}
- isPipeline, effParserID, effPipelineID := ResolveParseMode(&pt, &parserID, &pipelineID, cur)
+// Effective() for Pipeline returns the canvas id; the builtin parser_id is
+// ignored by the canvas DSL loader but is preserved for completeness.
+func TestParserSelection_EffectivePipeline(t *testing.T) {
+ sel := &ParserSelection{Mode: ParseModePipeline, ParserID: "general", PipelineID: "canvas-1"}
+ isPipeline, parserID, pipelineID := sel.Effective()
if !isPipeline {
- t.Fatalf("isPipeline = false, want true (pipeline mode)")
+ t.Fatalf("isPipeline = false, want true")
}
- if effParserID != "naive" {
- t.Fatalf("effParserID = %q, want current naive (parser_id not applicable in pipeline mode)", effParserID)
+ if parserID != "general" {
+ t.Fatalf("parserID = %q, want general", parserID)
}
- if effPipelineID == nil || *effPipelineID != pipelineID {
- t.Fatalf("effPipelineID = %v, want %q", effPipelineID, pipelineID)
+ if pipelineID == nil || *pipelineID != "canvas-1" {
+ t.Fatalf("pipelineID = %v, want canvas-1", pipelineID)
}
}
-func TestResolveParseMode_BuiltinFallsBackToCurrentParserID(t *testing.T) {
- pt := 1
- cur := ParseModeState{ParserID: "naive", PipelineID: strPtr("prior-canvas")}
- isPipeline, effParserID, effPipelineID := ResolveParseMode(&pt, nil, nil, cur)
- if isPipeline {
- t.Fatalf("isPipeline = true, want false")
+// CurrentSelection derives pipeline mode from a non-empty persisted pipeline_id.
+func TestCurrentSelection_Pipeline(t *testing.T) {
+ pid := "canvas-1"
+ sel := CurrentSelection("general", &pid)
+ if !sel.IsPipeline() {
+ t.Fatalf("expected pipeline selection, got %#v", sel)
+ }
+ if sel.ParserID != "general" || sel.PipelineID != "canvas-1" {
+ t.Fatalf("unexpected selection: %#v", sel)
}
- if effParserID != "naive" {
- t.Fatalf("effParserID = %q, want naive", effParserID)
+}
+
+func TestCurrentSelection_BuiltIn(t *testing.T) {
+ sel := CurrentSelection("general", nil)
+ if !sel.IsBuiltIn() {
+ t.Fatalf("expected builtin selection, got %#v", sel)
}
- if effPipelineID != nil {
- t.Fatalf("effPipelineID = %v, want nil", effPipelineID)
+ if sel.PipelineID != "" {
+ t.Fatalf("expected empty pipeline_id, got %q", sel.PipelineID)
}
}
-func TestResolveParseMode_PipelineFallsBackToCurrentPipelineID(t *testing.T) {
- pt := 2
- cur := ParseModeState{ParserID: "naive", PipelineID: strPtr("prior-canvas")}
- isPipeline, effParserID, effPipelineID := ResolveParseMode(&pt, nil, nil, cur)
- if !isPipeline {
- t.Fatalf("isPipeline = false, want true")
+func TestCurrentSelection_BuiltInEmptyPipelineID(t *testing.T) {
+ empty := ""
+ sel := CurrentSelection("general", &empty)
+ if !sel.IsBuiltIn() {
+ t.Fatalf("expected builtin selection, got %#v", sel)
}
- if effParserID != "naive" {
- t.Fatalf("effParserID = %q, want naive", effParserID)
+}
+
+// Resolve(create): current == nil requires a non-nil selection.
+func TestResolve_CreateRequiresSelection(t *testing.T) {
+ _, err := Resolve(nil, nil)
+ if err == nil || err.Error() != "parse_type is required" {
+ t.Fatalf("expected 'parse_type is required', got %v", err)
}
- if effPipelineID == nil || *effPipelineID != "prior-canvas" {
- t.Fatalf("effPipelineID = %v, want prior-canvas", effPipelineID)
+}
+
+// Resolve(create): current == nil, sel present -> returns sel.
+func TestResolve_CreateWithSelection(t *testing.T) {
+ sel := &ParserSelection{Mode: ParseModeBuiltIn, ParserID: "general"}
+ eff, err := Resolve(nil, sel)
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if eff != sel {
+ t.Fatalf("expected sel returned, got %#v", eff)
}
}
-// TestResolveParseMode_NilParseTypeInheritsCurrent covers the "only
-// parser_config changed" path: no mode switch, inherit current state.
-func TestResolveParseMode_NilParseTypeInheritsCurrent(t *testing.T) {
- t.Run("current is pipeline", func(t *testing.T) {
- cur := ParseModeState{ParserID: "naive", PipelineID: strPtr("canvas-1")}
- isPipeline, effParserID, effPipelineID := ResolveParseMode(nil, nil, nil, cur)
- if !isPipeline {
- t.Fatalf("isPipeline = false, want true")
- }
- if effParserID != "naive" {
- t.Fatalf("effParserID = %q, want naive", effParserID)
- }
- if effPipelineID == nil || *effPipelineID != "canvas-1" {
- t.Fatalf("effPipelineID = %v, want canvas-1", effPipelineID)
- }
- })
- t.Run("current is builtin", func(t *testing.T) {
- cur := ParseModeState{ParserID: "manual", PipelineID: nil}
- isPipeline, effParserID, effPipelineID := ResolveParseMode(nil, nil, nil, cur)
- if isPipeline {
- t.Fatalf("isPipeline = true, want false")
- }
- if effParserID != "manual" {
- t.Fatalf("effParserID = %q, want manual", effParserID)
- }
- if effPipelineID != nil {
- t.Fatalf("effPipelineID = %v, want nil", effPipelineID)
- }
- })
- t.Run("incremental parser_id update applied", func(t *testing.T) {
- cur := ParseModeState{ParserID: "naive", PipelineID: nil}
- newParser := "laws"
- isPipeline, effParserID, effPipelineID := ResolveParseMode(nil, &newParser, nil, cur)
- if isPipeline {
- t.Fatalf("isPipeline = true, want false")
- }
- if effParserID != "laws" {
- t.Fatalf("effParserID = %q, want laws", effParserID)
- }
- if effPipelineID != nil {
- t.Fatalf("effPipelineID = %v, want nil", effPipelineID)
- }
- })
+// Resolve(update): sel == nil keeps the current selection (PATCH omit).
+func TestResolve_UpdateOmitKeepsCurrent(t *testing.T) {
+ current := CurrentSelection("general", nil)
+ eff, err := Resolve(current, nil)
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if eff != current {
+ t.Fatalf("expected current kept, got %#v", eff)
+ }
+}
+
+// Resolve(update): sel overrides current (mode switch).
+func TestResolve_UpdateSwitchesMode(t *testing.T) {
+ current := CurrentSelection("general", nil)
+ pid := "canvas-1"
+ sel := &ParserSelection{Mode: ParseModePipeline, ParserID: "general", PipelineID: pid}
+ eff, err := Resolve(current, sel)
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if eff != sel || !eff.IsPipeline() {
+ t.Fatalf("expected pipeline sel returned, got %#v", eff)
+ }
+}
+
+// Resolve(update): sel overrides current (same-mode id change).
+func TestResolve_UpdateSameModeNewID(t *testing.T) {
+ current := CurrentSelection("general", nil)
+ sel := &ParserSelection{Mode: ParseModeBuiltIn, ParserID: "laws"}
+ eff, err := Resolve(current, sel)
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if eff != sel || eff.ParserID != "laws" {
+ t.Fatalf("expected builtin laws, got %#v", eff)
+ }
}
diff --git a/test/testcases/restful_api/helpers/client.py b/test/testcases/restful_api/helpers/client.py
index 1fac4e7aa9..f47aa9ba59 100644
--- a/test/testcases/restful_api/helpers/client.py
+++ b/test/testcases/restful_api/helpers/client.py
@@ -56,8 +56,22 @@ class RestClient:
# requests sets multipart boundary automatically.
req_headers.pop("Content-Type", None)
- timeout = request_kwargs.pop("timeout", self.timeout)
+ # The Go API requires parse_type on dataset creation (it explicitly
+ # selects BuiltIn (1) or Pipeline (2) mode). Historically a missing
+ # parse_type silently defaulted to BuiltIn/general; inject that
+ # previously-implicit default so dataset-create POSTs stay green without
+ # touching every call site. Tests that intentionally omit parse_type to
+ # assert the error path must pass parse_type explicitly.
normalized_path = f"/{path.lstrip('/')}" if path else "/"
+ if method == "POST" and normalized_path == "/datasets" and isinstance(json, dict) and "parse_type" not in json:
+ # Restore the previously-implicit default (BuiltIn/general) without
+ # clobbering any id the caller already supplied.
+ json = dict(json)
+ json["parse_type"] = 1
+ if "parser_id" not in json and "pipeline_id" not in json:
+ json["parser_id"] = "general"
+
+ timeout = request_kwargs.pop("timeout", self.timeout)
response = requests.request(
method=method,
url=f"{self.api_root}{normalized_path}",
diff --git a/web/src/components/builtin-pipeline-form-field.tsx b/web/src/components/builtin-pipeline-form-field.tsx
deleted file mode 100644
index 642d0c7adb..0000000000
--- a/web/src/components/builtin-pipeline-form-field.tsx
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import { SelectWithSearch } from '@/components/originui/select-with-search';
-import {
- FormControl,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from '@/components/ui/form';
-import { useFetchBuiltinPipelines } from '@/hooks/use-agent-request';
-import { cn } from '@/lib/utils';
-import { useFormContext } from 'react-hook-form';
-import { useTranslation } from 'react-i18next';
-
-export function BuiltinPipelineItem({
- line = 2,
- name = 'parser_id',
-}: {
- line?: 1 | 2;
- name?: string;
-}) {
- const { t } = useTranslation();
- const form = useFormContext();
- const { options: builtinPipelineOptions } = useFetchBuiltinPipelines();
-
- return (
- <FormField
- control={form.control}
- name={name}
- render={({ field }) => (
- <FormItem className="items-center space-y-0">
- <div
- className={cn('flex', {
- 'items-center': line === 1,
- 'flex-col gap-1': line === 2,
- })}
- >
- <FormLabel
- required
- className={cn('text-sm whitespace-wrap', {
- 'w-1/4': line === 1,
- })}
- >
- {t('knowledgeConfiguration.builtIn')}
- </FormLabel>
- <div
- className={cn('text-muted-foreground', { 'w-3/4': line === 1 })}
- >
- <FormControl>
- <SelectWithSearch
- {...field}
- placeholder={t(
- 'knowledgeConfiguration.chunkMethodPlaceholder',
- )}
- options={builtinPipelineOptions}
- />
- </FormControl>
- </div>
- </div>
- <div className="flex pt-1">
- <div className={line === 1 ? 'w-1/4' : ''}></div>
- <FormMessage />
- </div>
- </FormItem>
- )}
- />
- );
-}
diff --git a/web/src/components/data-pipeline-select/index.tsx b/web/src/components/data-pipeline-select/index.tsx
deleted file mode 100644
index 27610044ce..0000000000
--- a/web/src/components/data-pipeline-select/index.tsx
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import { AgentCategory } from '@/constants/agent';
-import { FormLayout } from '@/constants/form';
-import { useTranslate } from '@/hooks/common-hooks';
-import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';
-import { useFetchAgentList } from '@/hooks/use-agent-request';
-import { AgentListItem, AgentListItemType } from '@/interfaces/database/agent';
-import { buildSelectOptions } from '@/utils/component-util';
-import { ArrowUpRight } from 'lucide-react';
-import { useEffect, useMemo } from 'react';
-import { useFormContext } from 'react-hook-form';
-import { SelectWithSearch } from '../originui/select-with-search';
-import {
- FormControl,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from '../ui/form';
-import { MultiSelect } from '../ui/multi-select';
-export interface IDataPipelineSelectNode {
- id?: string;
- name?: string;
- avatar?: string;
-}
-
-interface IProps {
- showToDataPipeline?: boolean;
- formFieldName: string;
- isMult?: boolean;
- setDataList?: (data: IDataPipelineSelectNode[]) => void;
- layout?: FormLayout;
-}
-
-export function DataFlowSelect(props: IProps) {
- const {
- showToDataPipeline,
- formFieldName,
- isMult = false,
- setDataList,
- layout = FormLayout.Vertical,
- } = props;
-
- const { t } = useTranslate('knowledgeConfiguration');
- const form = useFormContext();
- const { navigateToAgents } = useNavigatePage();
- const toDataPipLine = () => {
- navigateToAgents();
- };
- const { data: dataPipelineOptions } = useFetchAgentList({
- canvas_category: AgentCategory.DataflowCanvas,
- });
-
- const canvasList = useMemo(
- () =>
- (dataPipelineOptions?.canvas ?? []).filter(
- (item): item is AgentListItem & { title: string; avatar?: string } =>
- item.type !== AgentListItemType.CompilationTemplateGroup,
- ),
- [dataPipelineOptions?.canvas],
- );
-
- const options = useMemo(() => {
- const option = buildSelectOptions(canvasList, 'id', 'title');
-
- return option || [];
- }, [canvasList]);
-
- const nodes = useMemo(() => {
- return (
- canvasList.map((item) => {
- return {
- id: item?.id,
- name: item?.title,
- avatar: item?.avatar,
- };
- }) || []
- );
- }, [canvasList]);
-
- useEffect(() => {
- setDataList?.(nodes);
- }, [nodes, setDataList]);
-
- return (
- <FormField
- control={form.control}
- name={formFieldName}
- render={({ field }) => (
- <FormItem className=" items-center space-y-0 ">
- {layout === FormLayout.Vertical && (
- <div className="flex flex-col gap-1">
- <div className="flex gap-2 justify-between ">
- <FormLabel
- // tooltip={t('dataFlowTip')}
- className="text-sm text-text-primary whitespace-wrap "
- required
- >
- {t('manualSetup')}
- </FormLabel>
- {showToDataPipeline && (
- <div
- className="text-sm flex text-text-primary cursor-pointer"
- onClick={toDataPipLine}
- >
- {t('buildItFromScratch')}
- <ArrowUpRight size={14} />
- </div>
- )}
- </div>
-
- <div className="text-muted-foreground">
- <FormControl>
- <>
- {!isMult && (
- <SelectWithSearch
- {...field}
- placeholder={t('dataFlowPlaceholder')}
- options={options}
- triggerClassName="!bg-bg-base"
- />
- )}
- {isMult && (
- <MultiSelect
- {...field}
- onValueChange={field.onChange}
- placeholder={t('dataFlowPlaceholder')}
- options={options}
- />
- )}
- </>
- </FormControl>
- </div>
- </div>
- )}
- {layout === FormLayout.Horizontal && (
- <div className="flex gap-1 items-center">
- <div className="flex gap-2 justify-between w-1/4">
- <FormLabel
- // tooltip={t('dataFlowTip')}
- className="text-sm text-text-secondary whitespace-wrap "
- >
- {t('manualSetup')}
- </FormLabel>
- </div>
-
- <div className="text-muted-foreground w-3/4 flex flex-col items-end">
- {showToDataPipeline && (
- <div
- className="text-sm flex text-text-primary cursor-pointer"
- onClick={toDataPipLine}
- >
- {t('buildItFromScratch')}
- <ArrowUpRight size={14} />
- </div>
- )}
- <FormControl>
- <>
- {!isMult && (
- <SelectWithSearch
- {...field}
- placeholder={t('dataFlowPlaceholder')}
- options={options}
- />
- )}
- {isMult && (
- <MultiSelect
- {...field}
- onValueChange={field.onChange}
- placeholder={t('dataFlowPlaceholder')}
- options={options}
- />
- )}
- </>
- </FormControl>
- </div>
- </div>
- )}
- <div className="flex pt-1">
- <FormMessage />
- </div>
- </FormItem>
- )}
- />
- );
-}
diff --git a/web/src/components/document-pipeline-dialog/index.tsx b/web/src/components/document-pipeline-dialog/index.tsx
index f67f72ab8e..07a0285e89 100644
--- a/web/src/components/document-pipeline-dialog/index.tsx
+++ b/web/src/components/document-pipeline-dialog/index.tsx
@@ -14,9 +14,7 @@
* limitations under the License.
*/
-import { BuiltinPipelineItem } from '@/components/builtin-pipeline-form-field';
-import { DataFlowSelect } from '@/components/data-pipeline-select';
-import { ParseTypeItem } from '@/components/parse-type-form-field';
+import { ParserSelect } from '@/components/parser-select';
import PipelineOperatorTabs from '@/components/pipeline-operator-tabs';
import { ButtonLoading } from '@/components/ui/button';
import {
@@ -26,13 +24,15 @@ import {
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
-import { Form } from '@/components/ui/form';
+import { Form, FormField, FormItem, FormMessage } from '@/components/ui/form';
import { ParseType } from '@/constants/knowledge';
import { IModalProps } from '@/interfaces/common';
import { IChangeParserRequestBody } from '@/interfaces/request/document';
import { useCallback } from 'react';
-import { FieldErrors, useFormState } from 'react-hook-form';
+import { FieldErrors, useFormState, useWatch } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
+import { buildParserOptionValue } from '@/hooks/use-parser-options';
+import { useParserSelectHandler } from '@/hooks/use-parser-select-handler';
import {
IDocumentPipelineDialogProps,
useDocumentPipelineForm,
@@ -68,6 +68,17 @@ export function DocumentPipelineDialog({
buildSubmitData,
} = useDocumentPipelineForm({ parserId, pipelineId, parserConfig });
+ const handleParserSelect = useParserSelectHandler(form);
+
+ const selectedParserId = useWatch({
+ control: form.control,
+ name: 'parser_id',
+ });
+ const selectedPipelineId = useWatch({
+ control: form.control,
+ name: 'pipeline_id',
+ });
+
const onSubmit = useCallback(
async (data: Parameters<typeof buildSubmitData>[0]) => {
const ret = await onOk?.(buildSubmitData(data));
@@ -107,15 +118,30 @@ export function DocumentPipelineDialog({
className="space-y-6 max-h-[70vh] overflow-auto -mx-6 px-10 py-5"
id={FormId}
>
- <ParseTypeItem />
- {parseType === ParseType.BuiltIn && <BuiltinPipelineItem />}
- {parseType === ParseType.Pipeline && (
- <DataFlowSelect
- isMult={false}
- showToDataPipeline={true}
- formFieldName="pipeline_id"
- />
- )}
+ <FormField
+ control={form.control}
+ name={
+ parseType === ParseType.BuiltIn ? 'parser_id' : 'pipeline_id'
+ }
+ render={() => (
+ <FormItem>
+ <ParserSelect
+ value={
+ parseType === ParseType.BuiltIn
+ ? buildParserOptionValue('builtin', selectedParserId)
+ : selectedPipelineId
+ ? buildParserOptionValue(
+ 'pipeline',
+ selectedPipelineId,
+ )
+ : undefined
+ }
+ onChange={handleParserSelect}
+ />
+ <FormMessage />
+ </FormItem>
+ )}
+ />
{showOperatorTabs && (
<PipelineOperatorTabs
nodes={operatorNodes}
diff --git a/web/src/components/document-pipeline-dialog/use-document-pipeline-form.ts b/web/src/components/document-pipeline-dialog/use-document-pipeline-form.ts
index de07d71206..0eeecdfefa 100644
--- a/web/src/components/document-pipeline-dialog/use-document-pipeline-form.ts
+++ b/web/src/components/document-pipeline-dialog/use-document-pipeline-form.ts
@@ -51,20 +51,20 @@ export function useDocumentPipelineForm({
() =>
z
.object({
- parseType: z.nativeEnum(ParseType),
+ parse_type: z.nativeEnum(ParseType),
parser_id: z.string(),
pipeline_id: z.string().optional(),
parser_config: z.record(z.string(), z.any()).optional(),
})
.superRefine((data, ctx) => {
- if (data.parseType === ParseType.BuiltIn && !data.parser_id.trim()) {
+ if (data.parse_type === ParseType.BuiltIn && !data.parser_id.trim()) {
ctx.addIssue({
path: ['parser_id'],
message: t('common.pleaseSelect'),
code: 'custom',
});
}
- if (data.parseType === ParseType.Pipeline && !data.pipeline_id) {
+ if (data.parse_type === ParseType.Pipeline && !data.pipeline_id) {
ctx.addIssue({
path: ['pipeline_id'],
message: t('common.pleaseSelect'),
@@ -79,7 +79,7 @@ export function useDocumentPipelineForm({
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
defaultValues: {
- parseType: pipelineId ? ParseType.Pipeline : ParseType.BuiltIn,
+ parse_type: pipelineId ? ParseType.Pipeline : ParseType.BuiltIn,
parser_id: parserId || '',
pipeline_id: pipelineId || '',
parser_config: transformSavedParserConfigToForm(parserConfig),
@@ -88,7 +88,7 @@ export function useDocumentPipelineForm({
const parseType = useWatch({
control: form.control,
- name: 'parseType',
+ name: 'parse_type',
});
const selectedDataFlowId = useWatch({
control: form.control,
@@ -177,12 +177,12 @@ export function useDocumentPipelineForm({
);
}
- const isPipeline = data.parseType === ParseType.Pipeline;
+ const isPipeline = data.parse_type === ParseType.Pipeline;
return {
parser_id: isPipeline ? '' : data.parser_id,
pipeline_id: isPipeline ? data.pipeline_id : '',
parser_config: transformedConfig,
- parseType: data.parseType,
+ parse_type: data.parse_type,
};
},
[],
diff --git a/web/src/components/parse-type-form-field.tsx b/web/src/components/parse-type-form-field.tsx
deleted file mode 100644
index e4d5f8c8f9..0000000000
--- a/web/src/components/parse-type-form-field.tsx
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import {
- FormControl,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from '@/components/ui/form';
-import { Radio } from '@/components/ui/radio';
-import { ParseType } from '@/constants/knowledge';
-import { cn } from '@/lib/utils';
-import { useFormContext } from 'react-hook-form';
-import { useTranslation } from 'react-i18next';
-
-export function ParseTypeItem({
- line = 2,
- name = 'parseType',
- builtInLabelKey = 'knowledgeConfiguration.builtIn',
- pipelineLabelKey = 'knowledgeConfiguration.manualSetup',
-}: {
- line?: number;
- name?: string;
- builtInLabelKey?: string;
- pipelineLabelKey?: string;
-}) {
- const { t } = useTranslation();
- const form = useFormContext();
-
- return (
- <FormField
- control={form.control}
- name={name}
- render={({ field }) => (
- <FormItem className="items-center space-y-0">
- <div
- className={cn('flex', {
- 'items-center': line === 1,
- 'flex-col gap-1': line === 2,
- })}
- >
- <FormLabel
- className={cn('text-sm whitespace-wrap ', {
- 'w-1/4': line === 1,
- })}
- >
- {t('knowledgeConfiguration.parseType')}
- </FormLabel>
- <div
- className={cn('text-muted-foreground', { 'w-3/4': line === 1 })}
- >
- <FormControl>
- <Radio.Group {...field}>
- <div
- className="flex w-full gap-8 text-muted-foreground"
- >
- <Radio value={ParseType.BuiltIn}>
- <span className="whitespace-nowrap">
- {t(builtInLabelKey)}
- </span>
- </Radio>
- <Radio value={ParseType.Pipeline}>
- <span className="whitespace-nowrap">
- {t(pipelineLabelKey)}
- </span>
- </Radio>
- </div>
- </Radio.Group>
- </FormControl>
- </div>
- </div>
- <div className="flex pt-1">
- <div className={line === 1 ? 'w-1/4' : ''}></div>
- <FormMessage />
- </div>
- </FormItem>
- )}
- />
- );
-}
diff --git a/web/src/components/parser-select/index.test.tsx b/web/src/components/parser-select/index.test.tsx
new file mode 100644
index 0000000000..aabd5c6324
--- /dev/null
+++ b/web/src/components/parser-select/index.test.tsx
@@ -0,0 +1,99 @@
+import { render } from '@testing-library/react';
+import { ParserSelect } from '@/components/parser-select';
+
+jest.mock('react-i18next', () => ({
+ useTranslation: () => ({ t: (k: string) => k }),
+}));
+
+const mockSelectProps: any = { onChange: jest.fn() };
+jest.mock('@/components/originui/select-with-search', () => ({
+ SelectWithSearch: (props: any) => {
+ mockSelectProps.value = props.value;
+ mockSelectProps.options = props.options;
+ mockSelectProps.loading = props.loading;
+ mockSelectProps.placeholder = props.placeholder;
+ mockSelectProps.onChange = props.onChange;
+ return <select data-testid="mock-select" />;
+ },
+}));
+
+jest.mock('@/hooks/use-parser-options', () => {
+ const parserOptions = {
+ options: [
+ { value: 'pipeline:pipe-1', label: 'My Flow', kind: 'pipeline' },
+ {
+ value: 'builtin:general',
+ label: 'General (built in)',
+ kind: 'builtin',
+ },
+ ],
+ loading: false,
+ };
+ return {
+ __setLoading: (v: boolean) => {
+ parserOptions.loading = v;
+ },
+ useParserOptions: () => parserOptions,
+ buildParserOptionValue: (kind: string, id: string) => `${kind}:${id}`,
+ parseParserOptionValue: (v?: string) => {
+ if (
+ !v ||
+ (v.startsWith('builtin:') === false &&
+ v.startsWith('pipeline:') === false)
+ ) {
+ return null;
+ }
+ const idx = v.indexOf(':');
+ return { kind: v.slice(0, idx), rawId: v.slice(idx + 1) };
+ },
+ };
+});
+
+// The mocked SelectWithSearch stores its (internal) onChange handler in
+// mockSelectProps.onChange. Firing it exercises ParserSelect's decode logic,
+// which calls the real user onChange we pass to ParserSelect below.
+beforeEach(() => {
+ mockSelectProps.onChange.mockClear?.();
+});
+
+describe('ParserSelect', () => {
+ it('passes the prefixed value through to the underlying select', () => {
+ render(<ParserSelect value="builtin:general" onChange={jest.fn()} />);
+ expect(mockSelectProps.value).toBe('builtin:general');
+ });
+
+ it('passes the merged option list through', () => {
+ render(<ParserSelect value={undefined} onChange={jest.fn()} />);
+ expect(mockSelectProps.options).toHaveLength(2);
+ expect(mockSelectProps.options[0].value).toBe('pipeline:pipe-1');
+ });
+
+ it('decodes a builtin selection into kind + rawId', () => {
+ const onChange = jest.fn();
+ render(<ParserSelect value={undefined} onChange={onChange} />);
+ mockSelectProps.onChange('builtin:general');
+ expect(onChange).toHaveBeenCalledWith('builtin', 'general');
+ });
+
+ it('decodes a pipeline selection into kind + rawId', () => {
+ const onChange = jest.fn();
+ render(<ParserSelect value={undefined} onChange={onChange} />);
+ mockSelectProps.onChange('pipeline:pipe-1');
+ expect(onChange).toHaveBeenCalledWith('pipeline', 'pipe-1');
+ });
+
+ it('emits null for an unrecognized/empty selection', () => {
+ const onChange = jest.fn();
+ render(<ParserSelect value={undefined} onChange={onChange} />);
+ mockSelectProps.onChange('garbage');
+ expect(onChange).toHaveBeenCalledWith(null, '');
+ });
+
+ it('forwards the loading flag from the options hook', () => {
+ const parserOptions = jest.requireMock('@/hooks/use-parser-options');
+ parserOptions.__setLoading(true);
+ render(<ParserSelect value={undefined} onChange={jest.fn()} />);
+ expect(mockSelectProps.loading).toBe(true);
+ parserOptions.__setLoading(false);
+ });
+});
diff --git a/web/src/components/parser-select/index.tsx b/web/src/components/parser-select/index.tsx
new file mode 100644
index 0000000000..dfd5c6cf2e
--- /dev/null
+++ b/web/src/components/parser-select/index.tsx
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { SelectWithSearch } from '@/components/originui/select-with-search';
+import {
+ parseParserOptionValue,
+ useParserOptions,
+ type ParserOptionKind,
+} from '@/hooks/use-parser-options';
+import { useCallback } from 'react';
+import { useTranslation } from 'react-i18next';
+
+interface IProps {
+ // Prefixed value produced by buildParserOptionValue, e.g. "builtin:general".
+ value?: string;
+ // Called with the resolved kind and the raw backend id on selection.
+ onChange: (kind: ParserOptionKind | null, rawId: string) => void;
+ placeholder?: string;
+ disabled?: boolean;
+}
+
+// ParserSelect is the single dropdown that merges pipeline (canvas) and builtin
+// parser options. It is a controlled component: the parent owns the form fields
+// and translates the kind/id pair into parser_id / pipeline_id / parse_type.
+export function ParserSelect({
+ value,
+ onChange,
+ placeholder,
+ disabled,
+}: IProps) {
+ const { t } = useTranslation();
+ const { options, loading } = useParserOptions();
+
+ const handleChange = useCallback(
+ (v: string) => {
+ const parsed = parseParserOptionValue(v);
+ if (!parsed) {
+ onChange(null, '');
+ return;
+ }
+ onChange(parsed.kind, parsed.rawId);
+ },
+ [onChange],
+ );
+
+ return (
+ <SelectWithSearch
+ value={value}
+ loading={loading}
+ // When the saved value references a parser that no longer exists (e.g. a
+ // deleted pipeline) and options have finished loading, render a localized
+ // "unavailable" label instead of the raw internal value.
+ renderMissingValue={() =>
+ t('knowledgeConfiguration.parserOptionUnavailable', {
+ defaultValue: 'unavailable',
+ })
+ }
+ onChange={handleChange}
+ placeholder={
+ placeholder ?? t('knowledgeConfiguration.parserSelectPlaceholder')
+ }
+ options={options}
+ disabled={disabled}
+ />
+ );
+}
diff --git a/web/src/hooks/use-document-request.ts b/web/src/hooks/use-document-request.ts
index 1f73b0140f..1d43031e2e 100644
--- a/web/src/hooks/use-document-request.ts
+++ b/web/src/hooks/use-document-request.ts
@@ -656,14 +656,14 @@ export const useSetDocumentPipelineParser = () => {
mutationFn: async ({
parserId,
pipelineId,
- parseType,
+ parse_type,
documentId,
datasetId,
parserConfig,
}: {
parserId: string;
pipelineId: string;
- parseType?: number;
+ parse_type?: number;
documentId: string;
datasetId: string;
parserConfig?: IChangeParserConfigRequestBody;
@@ -673,8 +673,8 @@ export const useSetDocumentPipelineParser = () => {
pipeline_id: pipelineId,
};
- if (parseType !== undefined) {
- updateData.parse_type = parseType;
+ if (parse_type !== undefined) {
+ updateData.parse_type = parse_type;
}
if (parserConfig) {
diff --git a/web/src/hooks/use-knowledge-request.ts b/web/src/hooks/use-knowledge-request.ts
index 55a6d4ad7e..ea455ac6b5 100644
--- a/web/src/hooks/use-knowledge-request.ts
+++ b/web/src/hooks/use-knowledge-request.ts
@@ -291,7 +291,7 @@ export const useCreateKnowledge = () => {
name: string;
embedding_model?: string;
chunk_method?: string;
- parseType?: ParseType;
+ parse_type?: ParseType;
pipeline_id?: string | null;
language?: string;
[key: string]: any;
diff --git a/web/src/hooks/use-parser-options.test.ts b/web/src/hooks/use-parser-options.test.ts
new file mode 100644
index 0000000000..84a7033785
--- /dev/null
+++ b/web/src/hooks/use-parser-options.test.ts
@@ -0,0 +1,159 @@
+import { renderHook } from '@testing-library/react';
+import { AgentListItemType } from '@/interfaces/database/agent';
+import {
+ buildParserOptionValue,
+ parseParserOptionValue,
+ useParserOptions,
+} from '@/hooks/use-parser-options';
+
+jest.mock('react-i18next', () => ({
+ useTranslation: () => ({
+ t: (key: string) =>
+ key === 'knowledgeConfiguration.builtInSuffix' ? ' (built in)' : key,
+ }),
+}));
+
+jest.mock('@/hooks/use-agent-request', () => ({
+ useFetchBuiltinPipelines: jest.fn(),
+ useFetchAgentList: jest.fn(),
+}));
+
+// eslint-disable-next-line @typescript-eslint/no-var-requires
+const agentRequest = require('@/hooks/use-agent-request');
+
+beforeEach(() => {
+ agentRequest.useFetchBuiltinPipelines.mockReturnValue({
+ options: [],
+ loading: false,
+ });
+ agentRequest.useFetchAgentList.mockReturnValue({
+ data: { canvas: [] },
+ loading: false,
+ });
+});
+
+describe('parser option value encoding', () => {
+ it('prefixes builtin and pipeline ids distinctly', () => {
+ expect(buildParserOptionValue('builtin', 'general')).toBe(
+ 'builtin:general',
+ );
+ expect(buildParserOptionValue('pipeline', 'abc123')).toBe(
+ 'pipeline:abc123',
+ );
+ });
+
+ it('round-trips builtin and pipeline values', () => {
+ expect(parseParserOptionValue('builtin:general')).toEqual({
+ kind: 'builtin',
+ rawId: 'general',
+ });
+ expect(parseParserOptionValue('pipeline:abc123')).toEqual({
+ kind: 'pipeline',
+ rawId: 'abc123',
+ });
+ });
+
+ it('keeps builtin and pipeline ids with the same bare value distinct', () => {
+ // A short builtin id and a pipeline id that happens to share the bare value
+ // must not collide once prefixed.
+ const builtin = buildParserOptionValue('builtin', 'general');
+ const pipeline = buildParserOptionValue('pipeline', 'general');
+ expect(builtin).not.toBe(pipeline);
+ expect(parseParserOptionValue(builtin)?.kind).toBe('builtin');
+ expect(parseParserOptionValue(pipeline)?.kind).toBe('pipeline');
+ });
+
+ it('handles ids that themselves contain a colon', () => {
+ const value = buildParserOptionValue('pipeline', 'a:b:c');
+ expect(value).toBe('pipeline:a:b:c');
+ expect(parseParserOptionValue(value)).toEqual({
+ kind: 'pipeline',
+ rawId: 'a:b:c',
+ });
+ });
+
+ it('returns null for empty or unprefixed values', () => {
+ expect(parseParserOptionValue('')).toBeNull();
+ expect(parseParserOptionValue(undefined)).toBeNull();
+ expect(parseParserOptionValue('general')).toBeNull();
+ expect(parseParserOptionValue('unknown:general')).toBeNull();
+ });
+});
+
+describe('useParserOptions merged list', () => {
+ it('puts pipeline options first, then builtin options with the suffix', () => {
+ agentRequest.useFetchBuiltinPipelines.mockReturnValue({
+ options: [
+ { label: 'General', value: 'general' },
+ { label: 'Book', value: 'book' },
+ ],
+ loading: false,
+ });
+ agentRequest.useFetchAgentList.mockReturnValue({
+ data: {
+ canvas: [
+ { id: 'pipe-1', title: 'My Flow', type: 'dataflow' },
+ { id: 'pipe-2', title: 'Other', type: 'dataflow' },
+ ],
+ },
+ loading: false,
+ });
+
+ const { result } = renderHook(() => useParserOptions());
+ const opts = result.current.options;
+
+ expect(opts).toHaveLength(4);
+ // Pipelines first, in original order.
+ expect(opts[0]).toEqual({
+ value: 'pipeline:pipe-1',
+ label: 'My Flow',
+ kind: 'pipeline',
+ });
+ expect(opts[1].value).toBe('pipeline:pipe-2');
+ // Builtin appended below with the " (built in)" suffix.
+ expect(opts[2]).toEqual({
+ value: 'builtin:general',
+ label: 'General (built in)',
+ kind: 'builtin',
+ });
+ expect(opts[3].label).toBe('Book (built in)');
+ });
+
+ it('excludes compilation template groups from pipeline options', () => {
+ agentRequest.useFetchAgentList.mockReturnValue({
+ data: {
+ canvas: [
+ { id: 'pipe-1', title: 'Real', type: 'dataflow' },
+ {
+ id: 'grp-1',
+ title: 'Group',
+ type: AgentListItemType.CompilationTemplateGroup,
+ },
+ ],
+ },
+ loading: false,
+ });
+
+ const { result } = renderHook(() => useParserOptions());
+ const pipelineOpts = result.current.options.filter(
+ (o) => o.kind === 'pipeline',
+ );
+ expect(pipelineOpts).toHaveLength(1);
+ expect(pipelineOpts[0].value).toBe('pipeline:pipe-1');
+ });
+
+ it('handles empty results from both sources', () => {
+ const { result } = renderHook(() => useParserOptions());
+ expect(result.current.options).toEqual([]);
+ expect(result.current.loading).toBe(false);
+ });
+
+ it('surfaces loading while either source is fetching', () => {
+ agentRequest.useFetchBuiltinPipelines.mockReturnValue({
+ options: [],
+ loading: true,
+ });
+ const { result } = renderHook(() => useParserOptions());
+ expect(result.current.loading).toBe(true);
+ });
+});
diff --git a/web/src/hooks/use-parser-options.ts b/web/src/hooks/use-parser-options.ts
new file mode 100644
index 0000000000..e904c40404
--- /dev/null
+++ b/web/src/hooks/use-parser-options.ts
@@ -0,0 +1,79 @@
+import { AgentCategory } from '@/constants/agent';
+import { AgentListItemType } from '@/interfaces/database/agent';
+import {
+ useFetchAgentList,
+ useFetchBuiltinPipelines,
+} from '@/hooks/use-agent-request';
+import { useMemo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+export type ParserOptionKind = 'builtin' | 'pipeline';
+
+export interface IParserOption {
+ value: string;
+ label: string;
+ kind: ParserOptionKind;
+}
+
+export const BuiltinPrefix = 'builtin:';
+export const PipelinePrefix = 'pipeline:';
+
+// buildParserOptionValue packs the parser kind and the raw backend id into a
+// single select value. Prefixing avoids collisions between short builtin ids
+// (e.g. "general") and 32-char canvas pipeline ids, and keeps the value safe
+// to serialize.
+export function buildParserOptionValue(kind: ParserOptionKind, rawId: string) {
+ return `${kind === 'builtin' ? BuiltinPrefix : PipelinePrefix}${rawId}`;
+}
+
+export function parseParserOptionValue(value?: string): {
+ kind: ParserOptionKind;
+ rawId: string;
+} | null {
+ if (!value) return null;
+ if (value.startsWith(BuiltinPrefix)) {
+ return { kind: 'builtin', rawId: value.slice(BuiltinPrefix.length) };
+ }
+ if (value.startsWith(PipelinePrefix)) {
+ return { kind: 'pipeline', rawId: value.slice(PipelinePrefix.length) };
+ }
+ return null;
+}
+
+// useParserOptions returns the unified list of parser options shown in the
+// merged dataset/document parser dropdown: pipeline (canvas) options first,
+// followed by builtin options each suffixed with the " (built in)" marker.
+export function useParserOptions() {
+ const { t } = useTranslation();
+ const { options: builtinOptions, loading: builtinLoading } =
+ useFetchBuiltinPipelines();
+ const { data: pipelineData, loading: pipelineLoading } = useFetchAgentList({
+ canvas_category: AgentCategory.DataflowCanvas,
+ });
+
+ const suffix = t('knowledgeConfiguration.builtInSuffix');
+
+ const options = useMemo<IParserOption[]>(() => {
+ const pipeline = (pipelineData?.canvas ?? [])
+ .filter(
+ (item) => item.type !== AgentListItemType.CompilationTemplateGroup,
+ )
+ .map((item) => ({
+ value: buildParserOptionValue('pipeline', item.id),
+ label: item.title,
+ kind: 'pipeline' as const,
+ }));
+
+ const builtin = builtinOptions.map((o) => ({
+ value: buildParserOptionValue('builtin', o.value),
+ label: `${o.label}${suffix}`,
+ kind: 'builtin' as const,
+ }));
+
+ // Pipeline options keep their existing order; builtin options are appended
+ // below, matching the desired "pipeline first, builtin (built in) below" UI.
+ return [...pipeline, ...builtin];
+ }, [pipelineData, builtinOptions, suffix]);
+
+ return { options, loading: builtinLoading || pipelineLoading };
+}
diff --git a/web/src/hooks/use-parser-select-handler.ts b/web/src/hooks/use-parser-select-handler.ts
new file mode 100644
index 0000000000..45fa2bcbb8
--- /dev/null
+++ b/web/src/hooks/use-parser-select-handler.ts
@@ -0,0 +1,28 @@
+import { useCallback } from 'react';
+import type { UseFormReturn } from 'react-hook-form';
+import { ParseType } from '@/constants/knowledge';
+import type { ParserOptionKind } from './use-parser-options';
+
+// useParserSelectHandler returns a stable onChange handler for ParserSelect that
+// maps the resolved (kind, rawId) pair onto the form's parser fields. Extracting
+// it keeps the duplicated logic in one place and avoids a fresh closure on every
+// render, which would otherwise defeat SelectWithSearch's memoization.
+export function useParserSelectHandler(form: UseFormReturn<any>) {
+ return useCallback(
+ (kind: ParserOptionKind | null, rawId: string) => {
+ if (kind === 'builtin') {
+ form.setValue('parse_type', ParseType.BuiltIn);
+ form.setValue('parser_id', rawId);
+ form.setValue('pipeline_id', '');
+ } else if (kind === 'pipeline') {
+ form.setValue('parse_type', ParseType.Pipeline);
+ form.setValue('pipeline_id', rawId);
+ form.setValue('parser_id', '');
+ } else {
+ form.setValue('parser_id', '');
+ form.setValue('pipeline_id', '');
+ }
+ },
+ [form],
+ );
+}
diff --git a/web/src/interfaces/request/document.ts b/web/src/interfaces/request/document.ts
index 8f0d39ee40..464edd91e6 100644
--- a/web/src/interfaces/request/document.ts
+++ b/web/src/interfaces/request/document.ts
@@ -40,7 +40,7 @@ export interface IChangeParserRequestBody {
parser_id: string;
pipeline_id?: string;
// 1 = BuiltIn (parser_id), 2 = Pipeline (pipeline_id); omitted = unspecified.
- parseType?: number;
+ parse_type?: number;
doc_id?: string;
parser_config: IChangeParserConfigRequestBody;
}
diff --git a/web/src/locales/ar.ts b/web/src/locales/ar.ts
index d414dcf807..b9c33b2f3f 100644
--- a/web/src/locales/ar.ts
+++ b/web/src/locales/ar.ts
@@ -423,6 +423,7 @@ export default {
reRankModelWaring: 'يستغرق نموذج إعادة التصنيف وقتًا طويلاً للغاية.',
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
globalIndexModelTip:
'يستخدم لإنشاء بيانات التعريف التلقائية والكلمات الرئيسية التلقائية والأسئلة التلقائية. سيؤثر أداء النموذج على جودة التوليد.',
globalIndexModel: 'نموذج الفهرسة',
diff --git a/web/src/locales/az.ts b/web/src/locales/az.ts
index c2478324f2..968076f5aa 100644
--- a/web/src/locales/az.ts
+++ b/web/src/locales/az.ts
@@ -683,6 +683,7 @@ Nümunə: 1024 ölçülü vektor təsviri olan 1 KB-lıq mesaj ~9 KB yer tutur.
reRankModelWaring: 'Yenidən sıralama modeli çox vaxt tələb edir.',
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
randomSeedTip:
'Başlanğıc dəyər eyni nəticənin müxtəlif icralarda təkrar əldə olunmasını təmin edən psevdotəsadüfi alqoritmin başlanğıc nöqtəsidir.',
datasetDescription: 'Verilənlər dəstinizi təsvir edin',
diff --git a/web/src/locales/bg.ts b/web/src/locales/bg.ts
index bee5092b47..726c843887 100644
--- a/web/src/locales/bg.ts
+++ b/web/src/locales/bg.ts
@@ -428,6 +428,7 @@ export default {
reRankModelWaring: 'Моделът за преподреждане е много времеемък.',
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
globalIndexModelTip:
'Използва се за генериране на авто-метаданни, авто-ключови думи и авто-въпроси. Производителността на модела влияе на качеството на генерирането.',
globalIndexModel: 'Индексиращ модел',
diff --git a/web/src/locales/de.ts b/web/src/locales/de.ts
index 0875399be9..4476f45b43 100644
--- a/web/src/locales/de.ts
+++ b/web/src/locales/de.ts
@@ -433,6 +433,7 @@ Beispiel: Eine 1 KB Nachricht mit 1024-dim Einbettung verwendet ~9 KB. Das Stand
reRankModelWaring: 'Das Rerank-Modell ist sehr zeitaufwendig.',
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
globalIndexModelTip:
'Wird verwendet, um Auto-Metadaten, Auto-Schlüsselwörter und Auto-Fragen zu generieren. Die Modellleistung beeinflusst die Generierungsqualität.',
globalIndexModel: 'Indizierungsmodell',
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index 593096ff49..95ee6f33a9 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -665,6 +665,9 @@ Example: A 1 KB message with 1024-dim embedding uses ~9 KB. The 5 MB default lim
reRankModelWaring: 'Re-rank model is very time consuming.',
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
+ parserSelectPlaceholder: 'Select a parser',
+ parserOptionUnavailable: 'unavailable',
randomSeedTip:
'Seed is the starting point for a pseudo-random algorithm that ensures reproducibility of the same output across different runs.',
datasetDescription: 'Describe your dataset',
diff --git a/web/src/locales/es.ts b/web/src/locales/es.ts
index 898aa080a1..f2c061cde0 100644
--- a/web/src/locales/es.ts
+++ b/web/src/locales/es.ts
@@ -169,6 +169,7 @@ export default {
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
paddleocrOptions: 'Opciones de PaddleOCR',
paddleocrApiUrl: 'URL de API de PaddleOCR',
paddleocrApiUrlTip:
diff --git a/web/src/locales/fr.ts b/web/src/locales/fr.ts
index 034ee73a5a..324fa4c746 100644
--- a/web/src/locales/fr.ts
+++ b/web/src/locales/fr.ts
@@ -590,6 +590,7 @@ export default {
'Le modèle de réordonnancement est très consommateur de temps.',
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
titleDescription:
'Modifiez ici la configuration de votre base de connaissances, notamment la méthode de découpage.',
imageTableContextWindow: 'Fenêtre de contexte image & tableau',
diff --git a/web/src/locales/id.ts b/web/src/locales/id.ts
index e353e4cf7b..4207e08770 100644
--- a/web/src/locales/id.ts
+++ b/web/src/locales/id.ts
@@ -172,6 +172,7 @@ export default {
html4excelTip: `Gunakan bersama dengan metode pemotongan General. Ketika dinonaktifkan, file spreadsheet (XLSX, XLS (Excel 97-2003)) akan dianalisis baris demi baris menjadi pasangan kunci-nilai. Ketika diaktifkan, file spreadsheet akan dianalisis menjadi tabel HTML. Jika tabel asli memiliki lebih dari 12 baris, sistem akan secara otomatis membagi menjadi beberapa tabel HTML setiap 12 baris. Untuk informasi lebih lanjut, lihat https://ragflow.io/docs/dataset_configuration#other-format-processing-configuration.`,
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
imageTableContextWindow: 'Jendela konteks gambar & tabel',
imageTableContextWindowTip:
'Mengambil N token teks di atas dan di bawah gambar dan tabel untuk memberikan konteks latar yang lebih kaya.',
diff --git a/web/src/locales/it.ts b/web/src/locales/it.ts
index 56354ec332..4b2af91a10 100644
--- a/web/src/locales/it.ts
+++ b/web/src/locales/it.ts
@@ -619,6 +619,7 @@ Esempio: un messaggio di 1 KB con embedding a 1024 dimensioni usa ~9 KB. Il limi
reRankModelWaring: 'Il modello re-rank richiede molto tempo.',
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
randomSeedTip:
'Il seme è il punto di partenza per un algoritmo pseudo-casuale che garantisce la riproducibilità dello stesso output in esecuzioni diverse.',
datasetDescription: 'Descrivi il tuo dataset',
diff --git a/web/src/locales/ja.ts b/web/src/locales/ja.ts
index d39057d1a4..f04482d8f8 100644
--- a/web/src/locales/ja.ts
+++ b/web/src/locales/ja.ts
@@ -392,6 +392,7 @@ export default {
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
imageTableContextWindow: '画像・表コンテキストウィンドウ',
imageTableContextWindowTip:
diff --git a/web/src/locales/ko.ts b/web/src/locales/ko.ts
index fcbe02f304..f76c4eda1a 100644
--- a/web/src/locales/ko.ts
+++ b/web/src/locales/ko.ts
@@ -607,6 +607,7 @@ export default {
reRankModelWaring: 'Re-rank 모델은 처리 시간이 매우 오래 걸립니다.',
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
randomSeedTip:
'Seed는 의사 난수 알고리즘의 시작점으로, 여러 실행에서 동일한 출력을 재현할 수 있도록 합니다.',
datasetDescription: '데이터셋을 설명하세요',
diff --git a/web/src/locales/pt-br.ts b/web/src/locales/pt-br.ts
index 1204e4ee9c..9ef79d9690 100644
--- a/web/src/locales/pt-br.ts
+++ b/web/src/locales/pt-br.ts
@@ -210,6 +210,7 @@ export default {
metaData: 'Metadados',
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
imageTableContextWindow: 'Janela de contexto de imagem e tabela',
imageTableContextWindowTip:
'Captura N tokens de texto acima e abaixo da imagem e da tabela para fornecer um contexto de fundo mais rico.',
diff --git a/web/src/locales/ru.ts b/web/src/locales/ru.ts
index fa48f149ff..baadb66064 100644
--- a/web/src/locales/ru.ts
+++ b/web/src/locales/ru.ts
@@ -447,6 +447,7 @@ export default {
reRankModelWaring: 'Rerank модель очень требовательна ко времени.',
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
randomSeedTip:
'Seed — начальное значение псевдослучайного алгоритма для воспроизводимости результата при повторных запусках.',
datasetDescription: 'Опишите ваш датасет',
diff --git a/web/src/locales/tr.ts b/web/src/locales/tr.ts
index de1868753b..5300cc49f6 100644
--- a/web/src/locales/tr.ts
+++ b/web/src/locales/tr.ts
@@ -670,6 +670,7 @@ Prosedürel Bellek: Öğrenilen beceriler, alışkanlıklar ve otomatik prosedü
reRankModelWaring: 'Yeniden sıralama modeli çok zaman alır.',
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
randomSeedTip:
'Tohum, farklı çalıştırmalarda aynı çıktının yeniden üretilebilirliğini sağlayan sözde rastgele bir algoritmanın başlangıç noktasıdır.',
datasetDescription: `Dataset'inizi açıklayın`,
diff --git a/web/src/locales/uz.ts b/web/src/locales/uz.ts
index 5028217473..1ab312ba01 100644
--- a/web/src/locales/uz.ts
+++ b/web/src/locales/uz.ts
@@ -671,6 +671,7 @@ export default {
reRankModelWaring: 'Rerank modeli juda ko‘p vaqt oladi.',
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
randomSeedTip:
'Urug‘ — bir xil natijalarning turli ishga tushirishlarda takrorlanuvchanligini ta’minlovchi psevdo-tasodifiy algoritmdir.',
datasetDescription: 'Ma’lumotlar to‘plamingizni tasvirlab bering',
diff --git a/web/src/locales/vi.ts b/web/src/locales/vi.ts
index 0593bd213b..24872ded76 100644
--- a/web/src/locales/vi.ts
+++ b/web/src/locales/vi.ts
@@ -191,6 +191,7 @@ export default {
documentMetaTips: `<p>Dữ liệu meta ở định dạng Json (không thể tìm kiếm). Nó sẽ được thêm vào prompt cho LLM nếu bất kỳ đoạn nào của tài liệu này được đưa vào prompt.</p> <p>Ví dụ:</p> <b>Dữ liệu meta là:</b><br> <code> { "Author": "Alex Dowson", "Date": "2024-11-12" } </code><br><b>Prompt sẽ là:</b><br> <p>Tài liệu: the_name_of_document</p> <p>Tác giả: Alex Dowson</p> <p>Ngày: 2024-11-12</p> <p>Các đoạn liên quan như sau:</p> <ul> <li> Đây là nội dung của đoạn...</li> <li> Đây là nội dung của đoạn...</li> </ul>`,
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
imageTableContextWindow: 'Cửa sổ ngữ cảnh hình ảnh & bảng',
imageTableContextWindowTip:
'Trích xuất N token văn bản phía trên và phía dưới hình ảnh và bảng để cung cấp bối cảnh phong phú hơn.',
diff --git a/web/src/locales/zh-traditional.ts b/web/src/locales/zh-traditional.ts
index bfae1c51c9..74ebec252f 100644
--- a/web/src/locales/zh-traditional.ts
+++ b/web/src/locales/zh-traditional.ts
@@ -217,6 +217,7 @@ export default {
theDocumentBeingParsedCannotBeDeleted: '正在解析的文檔不能被刪除',
},
knowledgeConfiguration: {
+ builtInSuffix: ' (built in)',
settings: '設置',
autoMetadataTip:
'自動生成元數據。適用於解析新文件。現有文件需要重新解析才能更新( chunk 將保留)。請注意,配置中指定的索引模型將消耗額外的 Token。',
diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts
index a97762e5bc..649c365713 100644
--- a/web/src/locales/zh.ts
+++ b/web/src/locales/zh.ts
@@ -604,6 +604,9 @@ export default {
theDocumentBeingParsedCannotBeDeleted: '正在解析的文档不能被删除',
},
knowledgeConfiguration: {
+ builtInSuffix: '(内置)',
+ parserSelectPlaceholder: '选择解析方式',
+ parserOptionUnavailable: '不可用',
randomSeedTip:
'种子是伪随机算法的起点,它确保在不同运行中产生相同的输出,从而保证可重复性。',
datasetDescription: '你的知识库描述。',
diff --git a/web/src/pages/dataset/dataset/use-change-document-parser.ts b/web/src/pages/dataset/dataset/use-change-document-parser.ts
index 8607f905e3..8d6a5b1ce8 100644
--- a/web/src/pages/dataset/dataset/use-change-document-parser.ts
+++ b/web/src/pages/dataset/dataset/use-change-document-parser.ts
@@ -25,7 +25,7 @@ export const useChangeDocumentParser = () => {
documentId: record?.id,
datasetId: record?.dataset_id,
parserConfig: parserConfigInfo.parser_config,
- parseType: parserConfigInfo.parseType,
+ parse_type: parserConfigInfo.parse_type,
});
if (ret === 0) {
hideChangeParserModal();
diff --git a/web/src/pages/dataset/setting/go/form-schema.ts b/web/src/pages/dataset/setting/go/form-schema.ts
index d9b9552adb..0cdc21046a 100644
--- a/web/src/pages/dataset/setting/go/form-schema.ts
+++ b/web/src/pages/dataset/setting/go/form-schema.ts
@@ -46,5 +46,12 @@ export const formSchema = z
code: 'custom',
});
}
+ if (data.parse_type === ParseType.BuiltIn && !data.parser_id?.trim()) {
+ ctx.addIssue({
+ path: ['parser_id'],
+ message: t('common.pleaseSelect'),
+ code: 'custom',
+ });
+ }
addParserConfigIssues(data.parser_config, ctx, t);
});
diff --git a/web/src/pages/dataset/setting/go/index.tsx b/web/src/pages/dataset/setting/go/index.tsx
index f6349874c0..6c765d477d 100644
--- a/web/src/pages/dataset/setting/go/index.tsx
+++ b/web/src/pages/dataset/setting/go/index.tsx
@@ -1,6 +1,4 @@
-import { BuiltinPipelineItem } from '@/components/builtin-pipeline-form-field';
-import { DataFlowSelect } from '@/components/data-pipeline-select';
-import { ParseTypeItem } from '@/components/parse-type-form-field';
+import { ParserSelect } from '@/components/parser-select';
import PipelineOperatorTabs from '@/components/pipeline-operator-tabs';
import { Button, ButtonLoading } from '@/components/ui/button';
import {
@@ -11,9 +9,16 @@ import {
CardTitle,
} from '@/components/ui/card';
import Divider from '@/components/ui/divider';
-import { Form } from '@/components/ui/form';
-import { FormLayout } from '@/constants/form';
+import {
+ Form,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from '@/components/ui/form';
import { ParseType } from '@/constants/knowledge';
+import { buildParserOptionValue } from '@/hooks/use-parser-options';
+import { useParserSelectHandler } from '@/hooks/use-parser-select-handler';
import {
useActiveTab,
usePipelineOperatorNodes,
@@ -59,6 +64,8 @@ export default function DatasetSetting() {
},
});
+ const handleParserSelect = useParserSelectHandler(form);
+
const {
knowledgeDetails,
loading: datasetSettingLoading,
@@ -214,18 +221,44 @@ export default function DatasetSetting() {
<div className="text-base font-medium text-text-primary">
{t('knowledgeConfiguration.dataPipeline')}
</div>
- <ParseTypeItem line={1} name="parse_type" />
- {parseType === ParseType.BuiltIn && (
- <BuiltinPipelineItem line={1} name="parser_id" />
- )}
- {parseType === ParseType.Pipeline && (
- <DataFlowSelect
- isMult={false}
- showToDataPipeline={true}
- formFieldName="pipeline_id"
- layout={FormLayout.Horizontal}
- />
- )}
+ <FormItem className="items-center space-y-0">
+ <div className="flex items-center gap-1">
+ <FormLabel className="text-sm text-text-secondary whitespace-wrap w-1/4">
+ {t('knowledgeConfiguration.parseType')}
+ </FormLabel>
+ <div className="text-muted-foreground w-3/4">
+ <FormField
+ control={form.control}
+ name={
+ parseType === ParseType.BuiltIn
+ ? 'parser_id'
+ : 'pipeline_id'
+ }
+ render={() => (
+ <FormItem className="space-y-1">
+ <ParserSelect
+ value={
+ parseType === ParseType.BuiltIn
+ ? buildParserOptionValue(
+ 'builtin',
+ builtinPipelineId ?? '',
+ )
+ : pipelineId
+ ? buildParserOptionValue(
+ 'pipeline',
+ pipelineId,
+ )
+ : undefined
+ }
+ onChange={handleParserSelect}
+ />
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ </div>
+ </FormItem>
{showOperatorTabs && (
<PipelineOperatorTabs
nodes={operatorNodes}
diff --git a/web/src/pages/datasets/dataset-creating-dialog.tsx b/web/src/pages/datasets/dataset-creating-dialog.tsx
index f6ec610458..e9ee96696d 100644
--- a/web/src/pages/datasets/dataset-creating-dialog.tsx
+++ b/web/src/pages/datasets/dataset-creating-dialog.tsx
@@ -1,6 +1,4 @@
-import { BuiltinPipelineItem } from '@/components/builtin-pipeline-form-field';
-import { DataFlowSelect } from '@/components/data-pipeline-select';
-import { ParseTypeItem } from '@/components/parse-type-form-field';
+import { ParserSelect } from '@/components/parser-select';
import { ButtonLoading } from '@/components/ui/button';
import {
Dialog,
@@ -19,8 +17,9 @@ import {
FormMessage,
} from '@/components/ui/form';
import { Input } from '@/components/ui/input';
-import { FormLayout } from '@/constants/form';
import { ParseType } from '@/constants/knowledge';
+import { buildParserOptionValue } from '@/hooks/use-parser-options';
+import { useParserSelectHandler } from '@/hooks/use-parser-select-handler';
import { useFetchDefaultModelDictionary } from '@/hooks/use-llm-request';
import { IModalProps } from '@/interfaces/common';
import { zodResolver } from '@hookform/resolvers/zod';
@@ -45,7 +44,7 @@ export function InputForm({ onOk }: IModalProps<any>) {
message: t('knowledgeList.namePlaceholder'),
})
.trim(),
- parseType: z.nativeEnum(ParseType).optional(),
+ parse_type: z.nativeEnum(ParseType).optional(),
embedding_model: z
.string()
.min(1, {
@@ -56,16 +55,16 @@ export function InputForm({ onOk }: IModalProps<any>) {
pipeline_id: z.string().optional(),
})
.superRefine((data, ctx) => {
- // When parseType === BuiltIn, parser_id is required
- if (data.parseType === ParseType.BuiltIn && !data.parser_id?.trim()) {
+ // When parse_type === BuiltIn, parser_id is required
+ if (data.parse_type === ParseType.BuiltIn && !data.parser_id?.trim()) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: t('knowledgeList.parserRequired'),
path: ['parser_id'],
});
}
- // When parseType === Pipeline, pipeline_id required
- if (data.parseType === ParseType.Pipeline && !data.pipeline_id) {
+ // When parse_type === Pipeline, pipeline_id required
+ if (data.parse_type === ParseType.Pipeline && !data.pipeline_id) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: t('knowledgeList.dataFlowRequired'),
@@ -78,17 +77,28 @@ export function InputForm({ onOk }: IModalProps<any>) {
resolver: zodResolver(FormSchema),
defaultValues: {
name: '',
- parseType: ParseType.BuiltIn,
- parser_id: '',
+ parse_type: ParseType.BuiltIn,
+ parser_id: 'general',
+ pipeline_id: '',
embedding_model: defaultModelDictionary?.embd_id,
},
});
const parseType = useWatch({
control: form.control,
- name: 'parseType',
+ name: 'parse_type',
+ });
+ const parserId = useWatch({
+ control: form.control,
+ name: 'parser_id',
+ });
+ const pipelineId = useWatch({
+ control: form.control,
+ name: 'pipeline_id',
});
+ const handleParserSelect = useParserSelectHandler(form);
+
function onSubmit(data: z.infer<typeof FormSchema>) {
const nextData =
parseType === ParseType.BuiltIn
@@ -97,12 +107,6 @@ export function InputForm({ onOk }: IModalProps<any>) {
onOk?.(nextData);
}
- useEffect(() => {
- if (parseType === ParseType.BuiltIn) {
- form.setValue('pipeline_id', '');
- }
- }, [parseType, form]);
-
// Backfill the default embedding model once the async query resolves, but
// never overwrite a model the user has already picked.
useEffect(() => {
@@ -138,21 +142,25 @@ export function InputForm({ onOk }: IModalProps<any>) {
/>
<EmbeddingModelItem line={2} isEdit={false} />
- <ParseTypeItem
- builtInLabelKey="knowledgeList.builtInTemplate"
- pipelineLabelKey="knowledgeList.ingestionPipeline"
+ <FormField
+ control={form.control}
+ name={parseType === ParseType.BuiltIn ? 'parser_id' : 'pipeline_id'}
+ render={() => (
+ <FormItem>
+ <ParserSelect
+ value={
+ parseType === ParseType.BuiltIn
+ ? buildParserOptionValue('builtin', parserId ?? '')
+ : pipelineId
+ ? buildParserOptionValue('pipeline', pipelineId)
+ : undefined
+ }
+ onChange={handleParserSelect}
+ />
+ <FormMessage />
+ </FormItem>
+ )}
/>
- {parseType === ParseType.BuiltIn && (
- <BuiltinPipelineItem name="parser_id" />
- )}
- {parseType === ParseType.Pipeline && (
- <DataFlowSelect
- isMult={false}
- showToDataPipeline={true}
- formFieldName="pipeline_id"
- layout={FormLayout.Vertical}
- />
- )}
</form>
</Form>
);
diff --git a/web/src/pages/datasets/hooks.ts b/web/src/pages/datasets/hooks.ts
index 9c9929a2ca..dfa3ca887c 100644
--- a/web/src/pages/datasets/hooks.ts
+++ b/web/src/pages/datasets/hooks.ts
@@ -19,7 +19,7 @@ export interface Iknowledge {
name: string;
embedding_model?: string;
chunk_method?: string;
- parseType?: ParseType;
+ parse_type?: ParseType;
pipeline_id?: string | null;
language?: string;
[key: string]: any;