feat(frontend): chunking debug panel with live preview

Adds a collapsible "Test with sample text" panel underneath the
chunking settings in the KB editor. Users paste a Markdown / plain-text
snippet, hit "Run preview", and see exactly how the current chunking
configuration would split it — without re-uploading any document.

The panel calls POST /api/v1/chunker/preview and renders:
- Selected tier (heading / heuristic / recursive / legacy) as a tag,
  with a warning when the chain fell through to legacy fallback
- Rejected tiers + reasons (so users see why "auto" picked tier X)
- DocProfile stats grid: lines, chars, headings, page-breaks,
  chapter markers, detected languages
- Chunk-size summary: count / avg / stddev / min / max
- Per-chunk cards with seq, size (chars + ~tokens), position range,
  context header (when set), content preview (expand/collapse)

The panel reads its config from the live form state so edits to
strategy / chunk-size / overlap / etc. are reflected on the next
preview run — no save needed.

Pieces:
- types/chunker.ts: TS types mirroring the backend response shape
- api/chunker/index.ts: previewChunking(body) wrapper
- views/knowledge/settings/KBChunkingDebug.vue: the panel component
- KBChunkingSettings.vue: embeds the panel + exposes a debugConfig
  computed prop
- i18n keys for en-US / zh-CN / ko-KR / ru-RU (8 keys each)

https://claude.ai/code/session_01XADhx6mtu2ZYW3DE9Lun6k
This commit is contained in:
Claude
2026-05-03 06:33:33 +00:00
committed by lyingbug
parent a867b1b29d
commit 6864a9f9e2
8 changed files with 692 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
// Chunker debug / preview API. Single endpoint that runs the adaptive
// chunker over a sample text without touching DB or embeddings. Used by
// the KB editor debug panel.
import { post } from '../../utils/request'
import type {
PreviewChunkingRequest,
PreviewChunkingResponse
} from '../../types/chunker'
export function previewChunking(
body: PreviewChunkingRequest
): Promise<{ success: boolean; data: PreviewChunkingResponse }> {
return post('/api/v1/chunker/preview', body)
}