Skip to content

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 ​

TableKey columnsNotes
kb_topicsid collection_id theme name canonical_name kind parent_id status importance chunks merged_from noteimportance defaults 0.6; kind defaults technical; parent_id points at a kind='group' row; merged_from is a JSON alias array
kb_topic_sourcesPK (topic_id, heading) · path document_id chunksmany-to-many topic↔source-section counts
kb_topic_mergesinto_topic from_name score reason decision decided_atdecision ∈ pending / accepted / rejected / reverted
kb_topic_proposalsmodel-curation proposalsfeeds /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 as title › 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) and looksLikeTopic (≤26 chars / ≤16 CJK + the TECH_TERMS vocabulary).

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:

  1. equal normalized names;
  2. equal sorted character multisets;
  3. prefix relation: both lengths ≥3 and suffix ≤2 chars or in the qualifier whitelist (机制|原理|参数…), with Latin-subject agreement;
  4. character-bigram Dice ≥ 0.85;
  5. 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: rebuildTopics matches old rows by collection_id | normalizeTopic(name) — user renames and notes survive; only counts and sources refresh.
  • Suggestion generation: within the same theme, different normalized names: sameTopic hit scores 0.8, else token overlap shared/min kept only if ≥0.45; max 3 per target, top 300 overall inserted as pending.
  • Accept appends the alias, moves sources, sets the absorbed row status='ignored', decision→accepted; undo restores it to active, 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), clamps importance to [0,1], note ≤200; the original name is 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 is IFG_PLAN_DEADLINE_MS default 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 focusKps then jdFocus.
  • 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.topic for fundamentals.

API ​

RoutePurpose
GET /kb/topicslist (collections / kind filters)
POST /kb/topics/rebuildrebuild graph + generate merge suggestions
PATCH /kb/topics/:idrename / importance / note
GET /kb/topics/merges · POST /merges/batch · POST /merges/:id/decision · POST /merges/:id/undo · GET /merges/recent · POST /mergesuggestion decisions / batch / undo / manual merge
GET /curate/preview · POST /curate · GET /hierarchy/preview · POST /hierarchy · GET /proposals · POST /proposals/:id/decisionmodel 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.

Local-first · inference egresses on demand · fully traceable