RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Feat: Add a toggle switch for the auto-question feature of the extractor operator. (#20748)
balibabu7270fa42e1b6
diff --git a/internal/ingestion/component/extractor.go b/internal/ingestion/component/extractor.goindex 771318474c..b2cd7624eb 100644--- a/internal/ingestion/component/extractor.go+++ b/internal/ingestion/component/extractor.go@@ -216,6 +216,11 @@ type ExtractorComponent struct {// "metadata": map[string]any, — optional auto metadata extraction config// }//+// The keywords/questions/tags groups accept an "enabled" switch. A group+// without the key is a legacy DSL: enabled derives from top_n > 0, matching+// the pre-switch behavior of saved canvases. A group carrying an explicit+// "enabled": true with top_n < 1 is a contradictory config and fails here.+//// errors here surface as canvas compile failures so a malformed// param is caught at build time rather than mid-run.func NewExtractorComponent(params map[string]any) (runtime.Component, error) {@@ -233,6 +238,11 @@ func NewExtractorComponent(params map[string]any) (runtime.Component, error) {if v, ok := kwRaw["system_prompt"].(string); ok {p.Keywords.SystemPrompt = v}+ enabled, err := resolveExtractToggle(kwRaw, "keywords", p.Keywords.TopN)+ if err != nil {+ return nil, err+ }+ p.Keywords.Enabled = enabled}// 2. Questions@@ -243,6 +253,11 @@ func NewExtractorComponent(params map[string]any) (runtime.Component, error) {if v, ok := qRaw["system_prompt"].(string); ok {p.Questions.SystemPrompt = v}+ enabled, err := resolveExtractToggle(qRaw, "questions", p.Questions.TopN)+ if err != nil {+ return nil, err+ }+ p.Questions.Enabled = enabled}// 3. Tags@@ -253,6 +268,11 @@ func NewExtractorComponent(params map[string]any) (runtime.Component, error) {if v, ok := tagRaw["tag_file_id"].(string); ok {p.Tags.TagFileID = v}+ enabled, err := resolveExtractToggle(tagRaw, "tags", p.Tags.TopN)+ if err != nil {+ return nil, err+ }+ p.Tags.Enabled = enabled}// 4. Summary@@ -289,6 +309,36 @@ func NewExtractorComponent(params map[string]any) (runtime.Component, error) {return &ExtractorComponent{Param: p}, nil}+// resolveExtractToggle resolves the enabled switch of one extraction group+// (keywords / questions / tags).+//+// The presence of the "enabled" key distinguishes the contract version:+// - key present: it is authoritative. enabled=true with top_n < 1 is a+// contradictory config (nothing could be extracted) and fails fast, so+// the canvas run dies at build time with a clear message instead of+// silently skipping the extraction.+// - key absent: legacy DSL saved before the switch existed — enabled+// derives from top_n > 0, preserving the saved canvas's behavior.+//+// Accepts bool and numeric "enabled" values, mirroring the summary/metadata+// parsing below.+func resolveExtractToggle(group map[string]any, name string, topN int) (bool, error) {+ v, ok := group["enabled"]+ if !ok {+ return topN > 0, nil+ }+ enabled := false+ if b, ok := v.(bool); ok {+ enabled = b+ } else {+ enabled = mapInt(v) == 1+ }+ if enabled && topN < 1 {+ return false, fmt.Errorf("extractor: %s.enabled requires top_n >= 1", name)+ }+ return enabled, nil+}+// Inputs returns the parameter metadata. Matches the python// Extractor._invoke kwargs plus the optional per-call llm_id// override (python: args["llm_id"] path is implicit via@@ -624,9 +674,9 @@ func (c *ExtractorComponent) Invoke(ctx context.Context, db *gorm.DB, inputs map}, nil}- keywordsOn := c.Param.Keywords.TopN > 0- tagsOn := c.Param.Tags.TopN > 0- remainingOn := c.Param.Questions.TopN > 0 || c.Param.Summary.Enabled || c.Param.Metadata.Enabled+ keywordsOn := c.Param.Keywords.Enabled+ tagsOn := c.Param.Tags.Enabled+ remainingOn := c.Param.Questions.Enabled || c.Param.Summary.Enabled || c.Param.Metadata.EnabledphaseWindows := newFractionSplit(keywordsOn, tagsOn, remainingOn)if err := runtime.WithTimeout(ctx, extractorTimeout, func(timeoutCtx context.Context) error {@@ -726,10 +776,10 @@ func (c *ExtractorComponent) runAutoKeywords(ctx context.Context, db *gorm.DB, iif _, exists := ck["important_kwd"]; exists {return nil}- topN := c.Param.Keywords.TopN- if topN <= 0 {+ if !c.Param.Keywords.Enabled {return nil}+ topN := c.Param.Keywords.TopNsystemPrompt := strings.TrimSpace(c.Param.Keywords.SystemPrompt)if systemPrompt == "" {systemPrompt = autoKeywordPrompt@@ -771,10 +821,10 @@ func (c *ExtractorComponent) runAutoQuestions(ctx context.Context, db *gorm.DB,if _, exists := ck["question_kwd"]; exists {return nil}- topN := c.Param.Questions.TopN- if topN <= 0 {+ if !c.Param.Questions.Enabled {return nil}+ topN := c.Param.Questions.TopNsystemPrompt := strings.TrimSpace(c.Param.Questions.SystemPrompt)if systemPrompt == "" {systemPrompt = autoQuestionPrompt@@ -896,7 +946,7 @@ func (s *fractionSplit) take(enabled bool) fractionWindow {// runAutoKeywordsPool dispatches keyword extraction across all chunks concurrently// using extractorPool before the tagging stage.func (c *ExtractorComponent) runAutoKeywordsPool(ctx context.Context, db *gorm.DB, in extractorInputs, w fractionWindow) error {- if c.Param.Keywords.TopN <= 0 || len(in.chunks) == 0 {+ if !c.Param.Keywords.Enabled || len(in.chunks) == 0 {return nil}futs := make([]utility.WorkerPoolFuture[extractorJob, struct{}], 0, len(in.chunks))@@ -924,7 +974,7 @@ func (c *ExtractorComponent) runAutoKeywordsPool(ctx context.Context, db *gorm.D// runRemainingExtractions dispatches auto questions / summary / metadata// extractions across all chunks concurrently using extractorPool.func (c *ExtractorComponent) runRemainingExtractions(ctx context.Context, db *gorm.DB, in extractorInputs, w fractionWindow) error {- if c.Param.Questions.TopN <= 0 && !c.Param.Summary.Enabled && !c.Param.Metadata.Enabled {+ if !c.Param.Questions.Enabled && !c.Param.Summary.Enabled && !c.Param.Metadata.Enabled {return nil}futs := make([]utility.WorkerPoolFuture[extractorJob, struct{}], 0, len(in.chunks))@@ -946,7 +996,7 @@ func (c *ExtractorComponent) runRemainingExtractions(ctx context.Context, db *gofunc (c *ExtractorComponent) remainingExtractionJob(ctx context.Context, db *gorm.DB, in extractorInputs, idx int, ck map[string]any, chunkText string) extractorJob {return func() error {- if c.Param.Questions.TopN > 0 {+ if c.Param.Questions.Enabled {if err := c.runAutoQuestions(ctx, db, in, ck, chunkText); err != nil {return fmt.Errorf("chunk %d questions: %w", idx, err)}diff --git a/internal/ingestion/component/extractor_cache_test.go b/internal/ingestion/component/extractor_cache_test.goindex 9e160168b8..1ad60b509b 100644--- a/internal/ingestion/component/extractor_cache_test.go+++ b/internal/ingestion/component/extractor_cache_test.go@@ -290,7 +290,7 @@ func TestExtractor_ResolvesDefaultModelOncePerRun(t *testing.T) {c := &ExtractorComponent{Param: schema.ExtractorParam{LLMID: "", // default-model path — the one #3 is about- Keywords: schema.KeywordExtractConfig{TopN: 3},+ Keywords: schema.KeywordExtractConfig{Enabled: true, TopN: 3},Metadata: schema.MetadataExtractConfig{Enabled: true,Metadata: []common.MetadataFieldDef{{Key: "category", Type: "string"}},diff --git a/internal/ingestion/component/extractor_test.go b/internal/ingestion/component/extractor_test.goindex b961329963..cb85b202be 100644--- a/internal/ingestion/component/extractor_test.go+++ b/internal/ingestion/component/extractor_test.go@@ -453,6 +453,95 @@ func TestExtractorComponent_NewExtractorComponent_Happy(t *testing.T) {}}+// TestExtractorComponent_ToggleDerivation covers the enabled-switch contract+// for keywords/questions/tags: an explicit "enabled" key is authoritative,+// a group without the key (legacy DSL) derives enabled from top_n > 0.+func TestExtractorComponent_ToggleDerivation(t *testing.T) {+ c, err := NewExtractorComponent(map[string]any{+ // legacy group: no enabled key, top_n > 0 → on+ "keywords": map[string]any{"top_n": 3},+ // legacy group: no enabled key, top_n = 0 → off+ "questions": map[string]any{"top_n": 0},+ // new contract: explicit switch wins over a positive top_n+ "tags": map[string]any{"enabled": false, "top_n": 5},+ })+ if err != nil {+ t.Fatalf("NewExtractorComponent: %v", err)+ }+ ext := c.(*ExtractorComponent)+ if !ext.Param.Keywords.Enabled {+ t.Errorf("legacy keywords top_n=3 should derive Enabled=true: %+v", ext.Param.Keywords)+ }+ if ext.Param.Questions.Enabled {+ t.Errorf("legacy questions top_n=0 should derive Enabled=false: %+v", ext.Param.Questions)+ }+ if ext.Param.Tags.Enabled || ext.Param.Tags.TopN != 5 {+ t.Errorf("explicit enabled=false must win over top_n=5 (kept for re-enable): %+v", ext.Param.Tags)+ }++ // Numeric enabled values are accepted like summary/metadata do.+ c, err = NewExtractorComponent(map[string]any{+ "keywords": map[string]any{"enabled": 1, "top_n": 2},+ })+ if err != nil {+ t.Fatalf("NewExtractorComponent numeric enabled: %v", err)+ }+ if !c.(*ExtractorComponent).Param.Keywords.Enabled {+ t.Error("enabled: 1 should parse as true")+ }+}++// TestExtractorComponent_ToggleOnWithoutTopNFails covers the contradictory+// new-contract config: enabled=true with top_n < 1 must fail at canvas build+// time for keywords/questions/tags alike.+func TestExtractorComponent_ToggleOnWithoutTopNFails(t *testing.T) {+ for _, group := range []string{"keywords", "questions", "tags"} {+ for _, topN := range []any{0, -2} {+ _, err := NewExtractorComponent(map[string]any{+ group: map[string]any{"enabled": true, "top_n": topN},+ })+ if err == nil {+ t.Errorf("%s enabled=true top_n=%v: expected error, got nil", group, topN)+ } else if !strings.Contains(err.Error(), group+".enabled requires top_n >= 1") {+ t.Errorf("%s enabled=true top_n=%v: unexpected error: %v", group, topN, err)+ }+ }+ // enabled=true with top_n absent entirely is the same contradiction.+ if _, err := NewExtractorComponent(map[string]any{+ group: map[string]any{"enabled": true},+ }); err == nil {+ t.Errorf("%s enabled=true without top_n: expected error, got nil", group)+ }+ }+}++// TestExtractorComponent_Invoke_ToggleOffSkipsExtraction verifies a group+// switched off (enabled=false) performs no LLM call even when top_n is set.+func TestExtractorComponent_Invoke_ToggleOffSkipsExtraction(t *testing.T) {+ stub := withStubChatInvoker(t, stubResponse{Content: "kw1, kw2"})++ c, err := NewExtractorComponent(map[string]any{+ "llm_id": "gpt-4o-mini",+ "keywords": map[string]any{"enabled": false, "top_n": 3},+ })+ if err != nil {+ t.Fatalf("NewExtractorComponent: %v", err)+ }+ out, err := c.(*ExtractorComponent).Invoke(t.Context(), nil, map[string]any{+ "chunks": []map[string]any{{"text": "first doc"}},+ })+ if err != nil {+ t.Fatalf("Invoke: %v", err)+ }+ if calls := stub.Calls(); calls != 0 {+ t.Errorf("LLM calls = %d, want 0 for a switched-off keywords group", calls)+ }+ chunks := out["chunks"].([]map[string]any)+ if _, exists := chunks[0]["important_kwd"]; exists {+ t.Errorf("switched-off keywords should not enrich the chunk: %#v", chunks[0])+ }+}+// TestExtractorComponent_InputsOutputs_NonEmpty verifies Inputs and Outputs shapes.func TestExtractorComponent_InputsOutputs_NonEmpty(t *testing.T) {c := &ExtractorComponent{}@@ -896,7 +985,7 @@ func TestExtractorComponent_Invoke_TemperatureSet(t *testing.T) {c := &ExtractorComponent{Param: schema.ExtractorParam{LLMID: "gpt-4o-mini",- Keywords: schema.KeywordExtractConfig{TopN: 3},+ Keywords: schema.KeywordExtractConfig{Enabled: true, TopN: 3},}}_, err := c.Invoke(t.Context(), nil, map[string]any{"chunks": []map[string]any{{"text": "document content"}},@@ -1089,8 +1178,8 @@ func TestExtractorComponent_Invoke_ConcurrentKeywordsAndQuestions(t *testing.T)c := &ExtractorComponent{Param: schema.ExtractorParam{LLMID: "gpt-4o-mini",- Keywords: schema.KeywordExtractConfig{TopN: 2},- Questions: schema.QuestionExtractConfig{TopN: 2},+ Keywords: schema.KeywordExtractConfig{Enabled: true, TopN: 2},+ Questions: schema.QuestionExtractConfig{Enabled: true, TopN: 2},}}out, err := c.Invoke(t.Context(), nil, map[string]any{"chunks": []map[string]any{diff --git a/internal/ingestion/component/schema/extractor.go b/internal/ingestion/component/schema/extractor.goindex 4a27f37268..379ffb154f 100644--- a/internal/ingestion/component/schema/extractor.go+++ b/internal/ingestion/component/schema/extractor.go@@ -75,19 +75,28 @@ type ExtractorFromUpstream struct {func (ExtractorFromUpstream) Validate() error { return nil }// KeywordExtractConfig configures automatic keyword extraction.+// Enabled is the single execution gate; TopN is the extraction count and+// must be >= 1 when Enabled (enforced at canvas build time for params that+// carry an explicit "enabled" key; legacy DSLs without it derive Enabled+// from TopN > 0 — see NewExtractorComponent).type KeywordExtractConfig struct {+ Enabled bool `json:"enabled"`TopN int `json:"top_n"`SystemPrompt string `json:"system_prompt,omitempty"`}// QuestionExtractConfig configures automatic question generation.+// Same Enabled/TopN contract as KeywordExtractConfig.type QuestionExtractConfig struct {+ Enabled bool `json:"enabled"`TopN int `json:"top_n"`SystemPrompt string `json:"system_prompt,omitempty"`}// TagExtractConfig configures automatic tag extraction.+// Same Enabled/TopN contract as KeywordExtractConfig.type TagExtractConfig struct {+ Enabled bool `json:"enabled"`TopN int `json:"top_n"`TagFileID string `json:"tag_file_id,omitempty"`}diff --git a/web/src/locales/en.ts b/web/src/locales/en.tsindex d4a5252855..d061f6e688 100644--- a/web/src/locales/en.ts+++ b/web/src/locales/en.ts@@ -3560,6 +3560,14 @@ This process aggregates variables from multiple branches into a single variablenodeFormInvalid: 'Invalid settings, please fix them first',agentModelMissing: 'No model selected, please choose one first',extractorModelMissing: 'No model selected, please choose one first',+ extractorKeywordsTopNMissing:+ 'Auto keywords is enabled, please set the number of keywords to extract (at least 1)',+ extractorQuestionsTopNMissing:+ 'Auto-question is enabled, please set the number of questions to generate (at least 1)',+ extractorTagsTopNMissing:+ 'Auto tags is enabled, please set the number of tags (at least 1)',+ extractorTagFileMissing:+ 'Auto tags is enabled, please select a tag file first',retrievalDatasetMissing: 'No dataset selected, please choose one first',retrievalMemoryMissing: 'No memories selected, please choose them first',checklist: 'Checklist',diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.tsindex 79cf236498..c194c9db3b 100644--- a/web/src/locales/zh.ts+++ b/web/src/locales/zh.ts@@ -3083,6 +3083,12 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 RnodeFormInvalid: '配置有误,请先修正',agentModelMissing: '未选择模型,请先选择',extractorModelMissing: '未选择模型,请先选择',+ extractorKeywordsTopNMissing:+ '自动关键词已开启,请设置抽取数量(至少为 1)',+ extractorQuestionsTopNMissing:+ '自动问题已开启,请设置生成数量(至少为 1)',+ extractorTagsTopNMissing: '自动标签已开启,请设置标签数量(至少为 1)',+ extractorTagFileMissing: '自动标签已开启,请先选择标签文件',retrievalDatasetMissing: '未选择知识库,请先选择',retrievalMemoryMissing: '未选择记忆,请先选择',checklist: '检查清单',diff --git a/web/src/pages/agent/constant/pipeline.tsx b/web/src/pages/agent/constant/pipeline.tsxindex aa8652cae3..84dae1a36f 100644--- a/web/src/pages/agent/constant/pipeline.tsx+++ b/web/src/pages/agent/constant/pipeline.tsx@@ -385,14 +385,17 @@ export const initialExtractorValues = {export const initialGoExtractorValues = {...initialLlmBaseValues,keywords: {+ enabled: false,top_n: 0,system_prompt: '',},questions: {+ enabled: false,top_n: 0,system_prompt: '',},tags: {+ enabled: false,top_n: 0,tag_file_id: '',},diff --git a/web/src/pages/agent/form/extractor-form/go-form.tsx b/web/src/pages/agent/form/extractor-form/go-form.tsxindex 4fa05b35f1..16d11c8229 100644--- a/web/src/pages/agent/form/extractor-form/go-form.tsx+++ b/web/src/pages/agent/form/extractor-form/go-form.tsx@@ -62,18 +62,21 @@ import { canSelectTagFile, useTagFileTree } from './use-tag-file-tree';export const FormSchema = z.object({keywords: z.object({+ enabled: z.union([z.number(), z.boolean()]).optional(),top_n: z.number().optional(),system_prompt: z.string().optional(),}).optional(),questions: z.object({+ enabled: z.union([z.number(), z.boolean()]).optional(),top_n: z.number().optional(),system_prompt: z.string().optional(),}).optional(),tags: z.object({+ enabled: z.union([z.number(), z.boolean()]).optional(),top_n: z.number().optional(),tag_file_id: z.string().optional(),})@@ -219,6 +222,18 @@ const GoExtractorForm = ({});const { treeData, loadData } = useTagFileTree(tagFileId);+ const keywordsEnabledRaw = useWatch({+ control: form.control,+ name: 'keywords.enabled',+ });+ const questionsEnabledRaw = useWatch({+ control: form.control,+ name: 'questions.enabled',+ });+ const tagsEnabledRaw = useWatch({+ control: form.control,+ name: 'tags.enabled',+ });const summaryEnabledRaw = useWatch({control: form.control,name: 'summary.enabled',@@ -227,6 +242,11 @@ const GoExtractorForm = ({control: form.control,name: 'metadata.enabled',});+ const keywordsEnabled =+ keywordsEnabledRaw === true || keywordsEnabledRaw === 1;+ const questionsEnabled =+ questionsEnabledRaw === true || questionsEnabledRaw === 1;+ const tagsEnabled = tagsEnabledRaw === true || tagsEnabledRaw === 1;const summaryEnabled = summaryEnabledRaw === true || summaryEnabledRaw === 1;const metadataEnabled =metadataEnabledRaw === true || metadataEnabledRaw === 1;@@ -249,6 +269,27 @@ const GoExtractorForm = ({}}, [form, t]);+ const handleKeywordsSwitch = useCallback(+ (checked: boolean) => {+ form.setValue('keywords.enabled', checked, { shouldDirty: true });+ },+ [form],+ );++ const handleQuestionsSwitch = useCallback(+ (checked: boolean) => {+ form.setValue('questions.enabled', checked, { shouldDirty: true });+ },+ [form],+ );++ const handleTagsSwitch = useCallback(+ (checked: boolean) => {+ form.setValue('tags.enabled', checked, { shouldDirty: true });+ },+ [form],+ );+const handleSummarySwitch = useCallback((checked: boolean) => {form.setValue('summary.enabled', checked, { shouldDirty: true });@@ -272,7 +313,17 @@ const GoExtractorForm = ({<div className="space-y-4"><Card as="section" className="bg-bg-card px-5 py-2.5 border-none">- <Collapse title={t('flow.keywords')} defaultOpen>+ <Collapse+ title={t('flow.keywords')}+ defaultOpen+ rightContent={+ <Switch+ checked={keywordsEnabled}+ onCheckedChange={handleKeywordsSwitch}+ data-testid="extractor-keywords-switch"+ />+ }+ ><div className="space-y-4"><AutoKeywordsFormField name="keywords.top_n" /><RAGFlowFormItem@@ -290,7 +341,17 @@ const GoExtractorForm = ({</Card><Card as="section" className="bg-bg-card px-5 py-2.5 border-none">- <Collapse title={t('flow.questions')} defaultOpen>+ <Collapse+ title={t('flow.questions')}+ defaultOpen+ rightContent={+ <Switch+ checked={questionsEnabled}+ onCheckedChange={handleQuestionsSwitch}+ data-testid="extractor-questions-switch"+ />+ }+ ><div className="space-y-4"><AutoQuestionsFormField name="questions.top_n" /><RAGFlowFormItem@@ -311,6 +372,13 @@ const GoExtractorForm = ({<Collapsetitle={t('flow.tags') || t('knowledgeDetails.autoTags')}defaultOpen+ rightContent={+ <Switch+ checked={tagsEnabled}+ onCheckedChange={handleTagsSwitch}+ data-testid="extractor-tags-switch"+ />+ }><div className="space-y-4"><SliderInputFormFielddiff --git a/web/src/pages/agent/utils.ts b/web/src/pages/agent/utils.tsindex fdfd84601b..df63ff27df 100644--- a/web/src/pages/agent/utils.ts+++ b/web/src/pages/agent/utils.ts@@ -535,6 +535,22 @@ function transformExtractorParamsGo(const tagsTopN = params.tags?.top_n ?? raw.auto_tags ?? 0;const tagFileId = params.tags?.tag_file_id ?? raw.tag_file_id ?? '';+ // The enabled switch is authoritative when the form carries it; an unopened+ // legacy node (flat keys only) derives it from top_n > 0, matching the Go+ // extractor's resolveExtractToggle.+ const isKeywordsEnabled =+ params.keywords?.enabled !== undefined+ ? Boolean(params.keywords.enabled)+ : keywordsTopN > 0;+ const isQuestionsEnabled =+ params.questions?.enabled !== undefined+ ? Boolean(params.questions.enabled)+ : questionsTopN > 0;+ const isTagsEnabled =+ params.tags?.enabled !== undefined+ ? Boolean(params.tags.enabled)+ : tagsTopN > 0;+// The Go extractor (schema.ExtractorParam) reads only llm_id plus the// nested per-feature groups, so emit exactly that whitelist along with// the LLM settings the form defines — no legacy flat mirrors, no@@ -542,14 +558,17 @@ function transformExtractorParamsGo(return {...pick(params, LlmSettingParamKeys),keywords: {+ enabled: isKeywordsEnabled,top_n: keywordsTopN,system_prompt: keywordsSysPrompt,},questions: {+ enabled: isQuestionsEnabled,top_n: questionsTopN,system_prompt: questionsSysPrompt,},tags: {+ enabled: isTagsEnabled,top_n: tagsTopN,tag_file_id: tagFileId,},diff --git a/web/src/pages/agent/utils/__tests__/canvas-checklist.test.ts b/web/src/pages/agent/utils/__tests__/canvas-checklist.test.tsindex bcf9ecdc35..16e863633c 100644--- a/web/src/pages/agent/utils/__tests__/canvas-checklist.test.ts+++ b/web/src/pages/agent/utils/__tests__/canvas-checklist.test.ts@@ -936,3 +936,74 @@ describe('collectCanvasIssues: compiler template group', () => {).toHaveLength(0);});});++describe('collectCanvasIssues: extractor extraction toggles', () => {+ const extractIssues = (form: Record<string, any>) =>+ collect({+ nodes: [+ makeNode('Extractor:e1', 'Extractor', { llm_id: 'model-1', ...form }),+ ],+ }).filter((x) => x.nodeId === 'Extractor:e1');++ it('flags an enabled keywords group whose top_n is not positive', () => {+ const issues = extractIssues({ keywords: { enabled: true, top_n: 0 } });++ expect(issues).toContainEqual(+ expect.objectContaining({+ type: CanvasIssueType.MissingRequired,+ messageKey: 'flow.extractorKeywordsTopNMissing',+ }),+ );+ });++ it('flags enabled questions and tags groups whose top_n is not positive', () => {+ const issues = extractIssues({+ questions: { enabled: true },+ tags: { enabled: true, top_n: -1, tag_file_id: 'tag-1' },+ });++ expect(issues).toContainEqual(+ expect.objectContaining({+ messageKey: 'flow.extractorQuestionsTopNMissing',+ }),+ );+ expect(issues).toContainEqual(+ expect.objectContaining({ messageKey: 'flow.extractorTagsTopNMissing' }),+ );+ // A tag file is selected, so no tag-file issue.+ expect(+ issues.some((x) => x.messageKey === 'flow.extractorTagFileMissing'),+ ).toBe(false);+ });++ it('flags an enabled tags group without a tag file', () => {+ const issues = extractIssues({ tags: { enabled: true, top_n: 3 } });++ expect(issues).toContainEqual(+ expect.objectContaining({ messageKey: 'flow.extractorTagFileMissing' }),+ );+ expect(+ issues.some((x) => x.messageKey === 'flow.extractorTagsTopNMissing'),+ ).toBe(false);+ });++ it('accepts switched-off groups and enabled groups with a positive top_n', () => {+ const issues = extractIssues({+ keywords: { enabled: false, top_n: 0 },+ questions: { enabled: true, top_n: 2 },+ tags: { enabled: true, top_n: 3, tag_file_id: 'tag-1' },+ });++ expect(+ issues.filter((x) => x.messageKey.startsWith('flow.extractor')),+ ).toHaveLength(0);+ });++ it('ignores legacy groups without the enabled key', () => {+ const issues = extractIssues({ keywords: { top_n: 0 } });++ expect(+ issues.filter((x) => x.messageKey.startsWith('flow.extractor')),+ ).toHaveLength(0);+ });+});diff --git a/web/src/pages/agent/utils/__tests__/extractor-transform.test.ts b/web/src/pages/agent/utils/__tests__/extractor-transform.test.tsindex 52eef04afa..ca112e74db 100644--- a/web/src/pages/agent/utils/__tests__/extractor-transform.test.ts+++ b/web/src/pages/agent/utils/__tests__/extractor-transform.test.ts@@ -45,14 +45,17 @@ describe('Extractor parameter transformations & precedence', () => {temperature: 0.5,temperatureEnabled: true,keywords: {+ enabled: true,top_n: 5,system_prompt: 'KW prompt',},questions: {+ enabled: true,top_n: 3,system_prompt: 'Q prompt',},tags: {+ enabled: true,top_n: 2,tag_file_id: 'tag-123',},@@ -83,9 +86,17 @@ describe('Extractor parameter transformations & precedence', () => {const result = transformExtractorParams(input);expect(result).toEqual({- keywords: { top_n: 4, system_prompt: 'legacy kw prompt' },- questions: { top_n: 2, system_prompt: 'legacy q prompt' },- tags: { top_n: 1, tag_file_id: 'tag-legacy' },+ keywords: {+ enabled: true,+ top_n: 4,+ system_prompt: 'legacy kw prompt',+ },+ questions: {+ enabled: true,+ top_n: 2,+ system_prompt: 'legacy q prompt',+ },+ tags: { enabled: true, top_n: 1, tag_file_id: 'tag-legacy' },summary: { enabled: true, system_prompt: 'legacy summary prompt' },metadata: { enabled: false, metadata: [], built_in_metadata: [] },});@@ -101,9 +112,9 @@ describe('Extractor parameter transformations & precedence', () => {const result = transformExtractorParams(input);expect(result).toEqual({- keywords: { top_n: 0, system_prompt: '' },- questions: { top_n: 0, system_prompt: '' },- tags: { top_n: 0, tag_file_id: '' },+ keywords: { enabled: false, top_n: 0, system_prompt: '' },+ questions: { enabled: false, top_n: 0, system_prompt: '' },+ tags: { enabled: false, top_n: 0, tag_file_id: '' },summary: { enabled: false, system_prompt: '' },metadata: {enabled: true,@@ -113,6 +124,33 @@ describe('Extractor parameter transformations & precedence', () => {});});+ it('keeps an explicit enabled switch authoritative over top_n', () => {+ const input: any = {+ keywords: { enabled: false, top_n: 5, system_prompt: '' },+ questions: { enabled: true, top_n: 2, system_prompt: '' },+ tags: { enabled: false, top_n: 3, tag_file_id: 'tag-1' },+ };++ const result = transformExtractorParams(input);++ // top_n survives a disabled switch so toggling back on restores it.+ expect(result.keywords).toEqual({+ enabled: false,+ top_n: 5,+ system_prompt: '',+ });+ expect(result.questions).toEqual({+ enabled: true,+ top_n: 2,+ system_prompt: '',+ });+ expect(result.tags).toEqual({+ enabled: false,+ top_n: 3,+ tag_file_id: 'tag-1',+ });+ });+it('accepts the transitional metadata_config key', () => {const input: any = {metadata_config: {@@ -186,8 +224,25 @@ describe('Extractor parameter transformations & precedence', () => {expect(result).not.toHaveProperty('enable_metadata');expect(result).not.toHaveProperty('built_in_metadata');expect(result.keywords.top_n).toBe(4);+ expect(result.keywords.enabled).toBe(true);expect(result.questions.top_n).toBe(2);+ expect(result.questions.enabled).toBe(true);expect(result.tags.top_n).toBe(1);+ expect(result.tags.enabled).toBe(true);+ });++ it('prefers an explicit group enabled over the top_n derivation', () => {+ const result = transformExtractorConfigToForm({+ keywords: { enabled: false, top_n: 5 },+ questions: { enabled: true, top_n: 0 },+ tags: { top_n: 0 },+ });++ // top_n is preserved so re-enabling restores the previous count.+ expect(result.keywords).toMatchObject({ enabled: false, top_n: 5 });+ expect(result.questions).toMatchObject({ enabled: true, top_n: 0 });+ // Legacy group without the switch derives from top_n.+ expect(result.tags).toMatchObject({ enabled: false, top_n: 0 });});it('passes through the metadata group shape unchanged', () => {diff --git a/web/src/pages/agent/utils/canvas-checklist.ts b/web/src/pages/agent/utils/canvas-checklist.tsindex 7e2ffbd7ef..31c653d8e3 100644--- a/web/src/pages/agent/utils/canvas-checklist.ts+++ b/web/src/pages/agent/utils/canvas-checklist.ts@@ -561,6 +561,39 @@ export function collectCanvasIssues({messageKey: 'flow.extractorModelMissing',});}+ // An extraction group switched on with nothing to extract (top_n < 1)+ // — or tags without a tag file — can be saved but would fail the Go+ // canvas build / silently skip at run time, so flag it here.+ if (form?.keywords?.enabled && !(Number(form?.keywords?.top_n) > 0)) {+ issues.push({+ ...target,+ type: CanvasIssueType.MissingRequired,+ messageKey: 'flow.extractorKeywordsTopNMissing',+ });+ }+ if (form?.questions?.enabled && !(Number(form?.questions?.top_n) > 0)) {+ issues.push({+ ...target,+ type: CanvasIssueType.MissingRequired,+ messageKey: 'flow.extractorQuestionsTopNMissing',+ });+ }+ if (form?.tags?.enabled) {+ if (!(Number(form?.tags?.top_n) > 0)) {+ issues.push({+ ...target,+ type: CanvasIssueType.MissingRequired,+ messageKey: 'flow.extractorTagsTopNMissing',+ });+ }+ if (!form?.tags?.tag_file_id) {+ issues.push({+ ...target,+ type: CanvasIssueType.MissingRequired,+ messageKey: 'flow.extractorTagFileMissing',+ });+ }+ }}if (label === Operator.Compiler) {diff --git a/web/src/utils/pipeline-operator.ts b/web/src/utils/pipeline-operator.tsindex ae22069e9b..1d7ce7dfec 100644--- a/web/src/utils/pipeline-operator.ts+++ b/web/src/utils/pipeline-operator.ts@@ -164,27 +164,46 @@ function transformExtractorConfigToFormGo(? Boolean(metadataGroup.enabled): config.enable_metadata === 1 || config.enable_metadata === true;+ // The enabled switch is authoritative when the group carries it; legacy+ // configs without it derive enabled from top_n > 0, matching the Go+ // extractor's resolveExtractToggle.+ const keywordsTopN =+ config.keywords?.top_n ??+ config.auto_keywords ??+ initialGoExtractorValues.keywords.top_n;+ const questionsTopN =+ config.questions?.top_n ??+ config.auto_questions ??+ initialGoExtractorValues.questions.top_n;+ const tagsTopN =+ config.tags?.top_n ??+ config.auto_tags ??+ initialGoExtractorValues.tags.top_n;+result.keywords = {- top_n:- config.keywords?.top_n ??- config.auto_keywords ??- initialGoExtractorValues.keywords.top_n,+ enabled:+ config.keywords?.enabled !== undefined+ ? Boolean(config.keywords.enabled)+ : keywordsTopN > 0,+ top_n: keywordsTopN,system_prompt:config.keywords?.system_prompt ?? config.keywords_sys_prompt ?? '',};result.questions = {- top_n:- config.questions?.top_n ??- config.auto_questions ??- initialGoExtractorValues.questions.top_n,+ enabled:+ config.questions?.enabled !== undefined+ ? Boolean(config.questions.enabled)+ : questionsTopN > 0,+ top_n: questionsTopN,system_prompt:config.questions?.system_prompt ?? config.questions_sys_prompt ?? '',};result.tags = {- top_n:- config.tags?.top_n ??- config.auto_tags ??- initialGoExtractorValues.tags.top_n,+ enabled:+ config.tags?.enabled !== undefined+ ? Boolean(config.tags.enabled)+ : tagsTopN > 0,+ top_n: tagsTopN,tag_file_id: config.tags?.tag_file_id ?? config.tag_file_id ?? '',};result.summary = {