fix(chunker): QA audit — pointer DTOs, profile reuse, stats correctness
Resolves the issues surfaced by the post-Phase-3 self-review. High severity - Strategy / TokenLimit / Languages can now be reset. The KB-config handler uses pointer DTOs so the absence of a field in the payload means "no change" while an explicit empty string / 0 / [] clears the value. The frontend now sends the fields unconditionally so the user can revert to defaults via the clear icon — previously these fields were write-once. - DocProfile is no longer computed twice in the preview endpoint. Diagnostics carries the profile that drove tier selection (when auto-strategy ran); the handler only re-profiles for explicit strategies that bypass the profiler. - Chunk-size stats (avg / min / max / stddev) are now computed over the FULL chunk set before the response is truncated to previewMaxChunks. Avoids systematically misleading metrics for large documents. - SplitWithDiagnostics defaults SelectedTier to TierLegacy so an empty-text request never leaves the diag with a blank tier string. Medium severity - Split() reverts to its own loop instead of delegating to SplitWithDiagnostics. Diagnostics struct allocation is reserved for callers that actually want the trace (preview endpoint). Matters in SplitParentChild where Split runs once per parent. - Preview endpoint runs the splitter on a goroutine wrapped in a 5s context.WithTimeout. CJK input at the 256k-rune ceiling could otherwise tie up the worker for several seconds. Low severity - KBChunkingSettings emits arrays via spread copies so parent-side mutation cannot drift the form's reactive state. - KBChunkingDebug font-family includes a monospace fallback so the chunk content stays monospaced even when the TDesign CSS variable is missing. Documentation - DocProfile JSON shape is now annotated as part of the public preview API; field renames would be breaking. https://claude.ai/code/session_01XADhx6mtu2ZYW3DE9Lun6k
This commit is contained in:
@@ -102,9 +102,14 @@ type KBModelConfigRequest struct {
|
||||
EnableParentChild bool `json:"enableParentChild"`
|
||||
ParentChunkSize int `json:"parentChunkSize,omitempty"`
|
||||
ChildChunkSize int `json:"childChunkSize,omitempty"`
|
||||
Strategy string `json:"strategy,omitempty"`
|
||||
TokenLimit int `json:"tokenLimit,omitempty"`
|
||||
Languages []string `json:"languages,omitempty"`
|
||||
// Strategy / TokenLimit / Languages use pointer types so the
|
||||
// handler can distinguish "field absent in payload" (no change)
|
||||
// from "field present with empty/zero value" (clear / disable).
|
||||
// Without that distinction, users could set strategy="auto" once
|
||||
// but never reset it back to legacy / unset.
|
||||
Strategy *string `json:"strategy,omitempty"`
|
||||
TokenLimit *int `json:"tokenLimit,omitempty"`
|
||||
Languages *[]string `json:"languages,omitempty"`
|
||||
} `json:"documentSplitting"`
|
||||
|
||||
// 多模态配置(仅模型相关;存储引擎在 storageProvider 中配置)
|
||||
@@ -323,14 +328,17 @@ func (h *InitializationHandler) UpdateKBConfig(c *gin.Context) {
|
||||
if req.DocumentSplitting.ChildChunkSize > 0 {
|
||||
kb.ChunkingConfig.ChildChunkSize = req.DocumentSplitting.ChildChunkSize
|
||||
}
|
||||
if req.DocumentSplitting.Strategy != "" {
|
||||
kb.ChunkingConfig.Strategy = req.DocumentSplitting.Strategy
|
||||
// Pointer-based fields support clearing (empty string / 0 / empty slice
|
||||
// is a valid "user picked default again" signal; absent in payload means
|
||||
// "no change").
|
||||
if req.DocumentSplitting.Strategy != nil {
|
||||
kb.ChunkingConfig.Strategy = *req.DocumentSplitting.Strategy
|
||||
}
|
||||
if req.DocumentSplitting.TokenLimit > 0 {
|
||||
kb.ChunkingConfig.TokenLimit = req.DocumentSplitting.TokenLimit
|
||||
if req.DocumentSplitting.TokenLimit != nil {
|
||||
kb.ChunkingConfig.TokenLimit = *req.DocumentSplitting.TokenLimit
|
||||
}
|
||||
if len(req.DocumentSplitting.Languages) > 0 {
|
||||
kb.ChunkingConfig.Languages = req.DocumentSplitting.Languages
|
||||
if req.DocumentSplitting.Languages != nil {
|
||||
kb.ChunkingConfig.Languages = *req.DocumentSplitting.Languages
|
||||
}
|
||||
|
||||
// 更新多模态配置
|
||||
|
||||
Reference in New Issue
Block a user