Expand description
Topic memory graph — incremental conversation topic map for prompt injection (B2).
Port of topic-memory-graph;
reference TS: docs/topic-memory-graph-main/src/.
Structs§
- Blocked
Point - Cognitive
Trail - Generate
Memory Section Options - Memory
Section Markers - Pheromone
Edge - Pheromone
Graph - Pheromone
Node - Topic
Memory Eval Comparison - Compare current metrics to a baseline file; used by
scripts/topic-memory-eval.ps1. - Topic
Memory Eval Report - B2.5 — derived rates for evaluation scripts and HTTP
/v1/topic-memory. - Topic
Memory Metrics - Sidecar metrics file:
metrics.jsonin the same directory as the graph file.
Enums§
Constants§
- DEFAULT_
INJECT_ INTERVAL_ RUNS - Default: inject after this many completed runs.
- DEFAULT_
MARKERS - DEFAULT_
RETRIEVE_ K_ HOPS - Default BFS depth from seed topics (UNDERLYING §2.3).
- GRAPH_
SCHEMA_ VERSION
Functions§
- apply_
decay - Apply time-based decay (at most once per calendar day).
- as_
system_ block - Wrap markdown in
<topic_memory>for system prompt assembly. - compare_
eval - detect_
blocked_ topics - Topics where the user expressed confusion / knowledge gaps.
- detect_
emotion - Detect dominant emotion from user text (≥2 signal hits for A/B/C, else N).
- empty_
graph - eval_
report - extract_
topics - Extract topic tokens from text (Chinese 2–6 char segments + English words ≥3).
- generate_
memory_ section - Markdown section for system prompt injection.
- induced_
subgraph - Build a subgraph containing only
nodesand edges between them. - inject_
memory_ section - Insert or replace a bounded memory section in markdown.
- load_
graph - Load graph from JSON path; returns empty graph when missing or invalid.
- load_
metrics - metrics_
path_ for_ graph - record_
inject - record_
turn_ update - Record a turn update; bumps clarification counters when topics repeat across turns.
- retrieve_
for_ query - Extract seeds from query text and return a k-hop subgraph.
- retrieve_
k_ hop_ subgraph - BFS k-hop neighborhood around
seeds(undirected over edge endpoints). - save_
graph - Persist graph atomically (best-effort).
- save_
metrics - Persist metrics atomically (best-effort).
- should_
inject_ memory - Whether enough runs have passed to inject memory into the prompt.
- today_
str - update_
graph - Update graph after one conversation turn.