Topic Graph
The Topic Graph distills section headings from the private knowledge base into a focusable, governable network of interview topics: extract → normalize → cluster → confidence-score → merge suggestions → human decision, finally consumed by interview planning and question generation. It is not a static tag list but a live graph with source counts, kind separation, hierarchy, and undoable merges.
Pipeline
Storage model
| Table | Key columns | Notes |
|---|---|---|
kb_topics | id collection_id theme name canonical_name kind parent_id status importance chunks merged_from note | importance defaults 0.6; kind defaults technical; parent_id points at a kind='group' row; merged_from is a JSON alias array |
kb_topic_sources | PK (topic_id, heading) · path document_id chunks | many-to-many topic↔source-section counts |
kb_topic_merges | into_topic from_name score reason decision decided_at | decision ∈ pending / accepted / rejected / reverted |
kb_topic_proposals | model-curation proposals | feeds /curate / /proposals decision flow |
Indexes cover (theme,status) (collection_id,status) (kind,status) (parent_id,status) sources(topic_id) merges(decision,into_topic).
Extraction & candidate filters
- Reuses structure-aware chunking: split on
^(#{1,4})\s+(H1–H4); chunk heading stored astitle › section. - Every section after the document title is a candidate; collections themed
原始素材(raw material) are skipped; headingless Q&A cards use the first line ≤30 chars. - Two filters:
isJunkTopic(length 2–24 + junk regexes) andlooksLikeTopic(≤26 chars / ≤16 CJK + theTECH_TERMSvocabulary).
Normalization
normalizeTopic applies NFKC + lowercase, then 16 word-boundary alias mappings (e.g. mvcc → 多版本并发控制), and strips trailing bracket annotations, numbering, punctuation, suffixes (详解|机制|原理…) and all 「的」. The normalized key drives clustering and rebuild matching.
Clustering: the five sameTopic rules
Union-find over normalized buckets (accelerated by a token index); two topics are the same iff any holds:
- equal normalized names;
- equal sorted character multisets;
- prefix relation: both lengths ≥3 and suffix ≤2 chars or in the qualifier whitelist (
机制|原理|参数…), with Latin-subject agreement; - character-bigram Dice ≥ 0.85;
- token Jaccard ≥ 0.75 with shared ≥3.
Cluster name = the highest-support heading; ties go to the shorter one.
kind & hierarchy
topicKind: theme ending in 复盘|求职材料|面试 or matching the narrative regex → project (project narrative); otherwise technical. parent_id attaches topics under kind='group' parents to form a hierarchy.
Confidence
score = chunks × factor, factor by source path: curated (src/(data|chapters) or qa|八股|考点) 1.6, noisy 0.4, else 1. Source counts let topics repeated across materials rise naturally.
Merge lifecycle
- Rebuild preserves renames:
rebuildTopicsmatches old rows bycollection_id | normalizeTopic(name)— user renames and notes survive; only counts and sources refresh. - Suggestion generation: within the same theme, different normalized names:
sameTopichit scores 0.8, else token overlapshared/minkept only if ≥0.45; max 3 per target, top 300 overall inserted aspending. - Accept appends the alias, moves sources, sets the absorbed row
status='ignored', decision→accepted; undo restores it toactive, subtracts its chunks, decision→reverted. - Batch accept default threshold
minScore 0.8; manual merge records score 1, reason人工合并. - Rename/governance: PATCH writes
canonical_name(≤60 chars), clampsimportanceto [0,1],note≤200; the originalnameis always kept so renames are reversible.
How interviews consume the graph
- The client picker sends
config.focusKps(≤20 entries, ≤200 chars each) to the Planner; if the focus comes from curated topics the planner run is skipped (PlanSkipped), otherwise the planner deadline isIFG_PLAN_DEADLINE_MSdefault 12000 ms (floor 4000). - Plan dedup: key = lowercase with whitespace/punctuation stripped; equal or mutual-prefix (both keys ≥4 chars) counts as duplicate; duplicates refill from
focusKpsthenjdFocus. - Post-generation dedup: same key/prefix rule; a duplicate question swaps to an unused same-type plan item, else gets the suffix 「(追问)」; curated topics override
q.topicfor fundamentals.
API
| Route | Purpose |
|---|---|
GET /kb/topics | list (collections / kind filters) |
POST /kb/topics/rebuild | rebuild graph + generate merge suggestions |
PATCH /kb/topics/:id | rename / importance / note |
GET /kb/topics/merges · POST /merges/batch · POST /merges/:id/decision · POST /merges/:id/undo · GET /merges/recent · POST /merge | suggestion decisions / batch / undo / manual merge |
GET /curate/preview · POST /curate · GET /hierarchy/preview · POST /hierarchy · GET /proposals · POST /proposals/:id/decision | model curation & hierarchy proposals (budget-gated) |
All verified via profileOf profile token; x-ifg-profile mismatch → 403.
Tests
Normalization / sameTopic constants, rebuild rename-persistence, curation validation, embedding clustering: server/tests/kernel.test.ts; focusKps-driven questions: server/tests/api.test.ts.