diff --git a/internal/application/service/knowledge_transfer_test.go b/internal/application/service/knowledge_transfer_test.go index 14cea13598c..e12b87aaa5f 100644 --- a/internal/application/service/knowledge_transfer_test.go +++ b/internal/application/service/knowledge_transfer_test.go @@ -387,6 +387,47 @@ func TestCopyServiceResumesReservedTargetAndRequiresTransferGrant(t *testing.T) require.ErrorIs(t, err, access.ErrForbidden) } +// A copy that creates its destination must index and process documents the +// way the source does. The settings below used to be left out, so the copy +// came up with the default strategy and every feature switched off. +func TestCopyServiceCarriesIndexingStrategyAndFeatureSettings(t *testing.T) { + repo := newFakeKBRepo() + source := &types.KnowledgeBase{ + ID: "src", TenantID: 1, Type: types.KnowledgeBaseTypeDocument, + IndexingStrategy: types.IndexingStrategy{KeywordEnabled: true, WikiEnabled: true, GraphEnabled: true}, + ASRConfig: types.ASRConfig{Enabled: true, ModelID: "asr-1", Language: "zh"}, + ExtractConfig: &types.ExtractConfig{ + Enabled: true, Text: "extract entities", Tags: []string{"product"}, + Nodes: []*types.GraphNode{{Name: "Product"}}, + }, + WikiConfig: &types.WikiConfig{SynthesisModelID: "wiki-llm", MaxPagesPerIngest: 12}, + QuestionGenerationConfig: &types.QuestionGenerationConfig{Enabled: true, QuestionCount: 5}, + AutoTagConfig: &types.AutoTagConfig{Enabled: true, MaxTags: 3}, + } + repo.rows["src"] = source + svc := newPR3KBService(repo, &fakeRegistry{}, &fakeOwnership{}) + ctx, err := access.WithKBTransferTask( + context.Background(), + source, + &types.KnowledgeBase{ID: "copy", TenantID: 1}, + 1, + access.KBTransferClone, + "task", + true, + ) + require.NoError(t, err) + + _, target, err := svc.CopyKnowledgeBase(ctx, "src", "copy") + require.NoError(t, err) + require.Equal(t, source.IndexingStrategy, target.IndexingStrategy) + require.Equal(t, source.ASRConfig, target.ASRConfig) + require.Equal(t, source.ExtractConfig, target.ExtractConfig) + require.Equal(t, source.WikiConfig, target.WikiConfig) + require.Equal(t, source.QuestionGenerationConfig, target.QuestionGenerationConfig) + require.Equal(t, source.AutoTagConfig, target.AutoTagConfig) + require.NotSame(t, source.ExtractConfig, target.ExtractConfig, "the copy must own its settings") +} + func TestProcessingCannotEnterClaimedMoveBeforeKBBindingChanges(t *testing.T) { f := transferFixture(t, access.KBTransferMove) row, err := f.repo.GetKnowledgeByID(f.ctx, 7, "doc") diff --git a/internal/application/service/knowledgebase.go b/internal/application/service/knowledgebase.go index 436765f5cf6..b496dfb8fd5 100644 --- a/internal/application/service/knowledgebase.go +++ b/internal/application/service/knowledgebase.go @@ -1491,6 +1491,15 @@ func (s *knowledgeBaseService) CopyKnowledgeBase(ctx context.Context, cfg := *sourceKB.ProfileConfig profileConfig = &cfg } + // The indexing strategy and the per-feature settings decide how the + // copy indexes and processes documents, so they come along too, as the + // same deep copy DuplicateKnowledgeBase starts from. Left out, the copy + // fell back to vector+keyword with wiki, graph, generated questions, + // auto-tagging and transcription all off. + settings, err := cloneKnowledgeBaseConfiguration(sourceKB) + if err != nil { + return nil, nil, err + } // Preserve VectorStoreID so the cloned KB lands on the same // physical index. GORM `<-:create` permits the value at INSERT. targetKB = &types.KnowledgeBase{ @@ -1511,6 +1520,13 @@ func (s *knowledgeBaseService) CopyKnowledgeBase(ctx context.Context, FAQConfig: faqConfig, ProfileConfig: profileConfig, VectorStoreID: sourceKB.VectorStoreID, + + IndexingStrategy: settings.IndexingStrategy, + ASRConfig: settings.ASRConfig, + ExtractConfig: settings.ExtractConfig, + WikiConfig: settings.WikiConfig, + QuestionGenerationConfig: settings.QuestionGenerationConfig, + AutoTagConfig: settings.AutoTagConfig, } // The clone is owned by the caller, not the original creator — // otherwise a Contributor copying someone else's KB would still