Skip to content

fix(knowledge): keep the indexing strategy and feature settings on a KB copy - #6233

Open
columbia11 wants to merge 1 commit into
Tencent:mainfrom
columbia11:fix/kb-copy-keeps-configs
Open

columbia11 wants to merge 1 commit into
Tencent:mainfrom
columbia11:fix/kb-copy-keeps-configs

Conversation

@columbia11

Copy link
Copy Markdown
Contributor

Description

POST /api/v1/knowledge-bases/copy without a target_id creates the destination knowledge base and copies the documents into it. The new knowledge base does not get the source's indexing strategy or its per-feature settings, so it indexes and processes documents differently from the knowledge base it was copied from, with nothing in the task result saying so.

For a source with keyword search, wiki and graph enabled (vector off), the copy comes out as:

Setting Source Copy
indexing_strategy keyword, wiki, graph vector, keyword
extract_config (graph prompt, tags, node and relation types) set empty
wiki_config set empty
question_generation_config set empty
auto_tag_config set empty
asr_config set empty

Documents uploaded to the copy afterwards get no graph extraction, no wiki pages, no generated questions, no auto-tagging and no transcription, and the extraction prompt and schema have to be re-entered by hand.

Cause

CopyKnowledgeBase builds the new knowledge base from a field-by-field literal. The literal predates these settings, and they were never added to it (VectorStoreID, StorageBackendID and ProfileConfig were). EnsureDefaults then fills the empty IndexingStrategy with the default.

DuplicateKnowledgeBase (the settings-only copy the web UI uses) clones the whole configuration and is not affected.

Change

The create branch of CopyKnowledgeBase now also sets IndexingStrategy, ASRConfig, ExtractConfig, WikiConfig, QuestionGenerationConfig and AutoTagConfig, taken from the same deep copy DuplicateKnowledgeBase starts from (cloneKnowledgeBaseConfiguration).

Copying into an existing target_id is unchanged: that knowledge base keeps its own settings.

Not changed, and worth knowing when reviewing: the copy task still transfers documents, chunks and index rows only. Wiki pages and graph data of the source are not copied and are not regenerated for the copied documents, before or after this PR. With this PR the copy has the wiki and graph settings, so documents added later are processed like in the source. That is the state a copy into an existing wiki- or graph-enabled knowledge base is already in today, so it is not a new one. Queueing wiki generation for the copied documents (the document move path does this) would be a separate change.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📚 Documentation update
  • 🎨 Refactor
  • ⚡ Performance improvement
  • 🧪 Test
  • 🔧 Configuration / Build / CI

Related Issue

None found.

Testing

New test TestCopyServiceCarriesIndexingStrategyAndFeatureSettings in internal/application/service/knowledge_transfer_test.go: copy a source that has all six settings into a new destination and compare each one; the copy must also own its ExtractConfig rather than share the source's.

With main's knowledgebase.go it fails on the first comparison:

expected: types.IndexingStrategy{VectorEnabled:false, KeywordEnabled:true, WikiEnabled:true, GraphEnabled:true}
actual  : types.IndexingStrategy{VectorEnabled:true, KeywordEnabled:true, WikiEnabled:false, GraphEnabled:false}

With the change it passes.

Commands, run in WSL (Ubuntu 24.04, Go 1.26.7, cgo on):

  • go test ./internal/application/service/ -count=1 → ok.
  • go vet ./internal/application/service/ → clean. gofmt -l on the two files → no output.
  • golangci-lint run --new-from-patch=<git diff origin/main> on the package with golangci-lint v2.12.2 → 0 issues.
  • git diff --check origin/main...HEAD → clean.

Not run: make test / make lint for the whole repository, and the endpoint was not called against a running server.

Checklist

  • git diff --check origin/main...HEAD passes
  • Changed source files are formatted
  • Targeted tests for the changed packages/components pass
  • Diff-scoped lint passes where applicable (for Go: golangci-lint run --new-from-rev=origin/main ./...) — run as --new-from-patch
  • Full-repository checks were run, or any unrelated/environment-dependent failures are documented above — not run; scoped to internal/application/service
  • Self-reviewed the code
  • Added/updated tests covering the change
  • Updated related documentation (README, website-docs/, Swagger annotations, etc.) — none needed
  • Breaking changes are clearly called out in the description above — none

Screenshots / Recordings

Not a UI change.

…KB copy

CopyKnowledgeBase created the destination from a field-by-field literal that
left out IndexingStrategy, ExtractConfig, WikiConfig,
QuestionGenerationConfig, AutoTagConfig and ASRConfig. The copy came up with
the default vector+keyword strategy and wiki, graph, generated questions,
auto-tagging and transcription switched off, whatever the source had.

Take those settings from the same deep copy DuplicateKnowledgeBase uses.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant