Expand description
#2 knowledge graph: rule-based relation-edge extraction.
Consolidation writes "supersedes" edges, but those point at superseded
memories retrieval already excludes, so on their own they leave the
graph-lite / petgraph backends behaving exactly like flat retrieval. This
module derives MEANINGFUL "relates_to" edges between active memories
that share a salient entity, so a query that hits memory A can reach a linked
memory B it does not directly match (multi-hop retrieval).
The rule layer is fully deterministic and model-free: it parses inline
[tags: ...] markers (via crate::consolidate::parse_tags) plus a small
salient-term pass, indexes memories by entity, and links every pair that
shares at least one entity. The optional LLM enrichment layer (--enrich)
lives in the CLI, where the cheap-model provider is resolved.
§Batch vs incremental (v2.6)
build_relates_to_edges rebuilds the whole graph and is what
kimetsu brain graph build runs. Because it only ever ran when a user
remembered to invoke it, memory_edges in practice held nothing but
supersedes — so the graph-lite backend behaved like flat retrieval, and
the published graph-lite benchmark number described a configuration almost
nobody was running.
incremental_edges_for_memory closes that gap: one indexed lookup against
the memory_entities projection, run on every write, bounded by the same
fan-out cap. It asks for INCREMENTAL_MIN_SHARED_ENTITIES shared entities
rather than the batch builder’s one, because a single shared word on the
write path would attach each new memory to half the corpus.
Edges are persisted as memory.edge events via
crate::projector::add_memory_edges, so they are rebuild-safe.
Structs§
- Edge
Proposal - A proposed relation edge between two active memories.
Enums§
- Entity
Source - Where an extracted entity came from. Author-supplied tags are high-signal; salient terms are the extractor’s guess. Ranking treats them differently, so the distinction is persisted rather than recomputed.
Constants§
- DEFAULT_
MAX_ FAN_ OUT - Default cap on how many edges any single memory may originate, to stop a common entity (shared by many memories) from producing a quadratic hairball.
- INCREMENTAL_
MIN_ SHARED_ ENTITIES - Minimum shared entities before two memories are linked on the write path.
- RELATES_
TO - The rule-layer edge type.
Functions§
- build_
relates_ to_ edges - Build rule-based
relates_toedge proposals over all active memories: any two memories sharing >= 1 extracted entity are linked. Edges are undirected in meaning but stored once assrc < dst(graph-lite traverses both directions), so each related pair yields exactly one proposal.max_fan_outcaps the number of edges per source memory (0 = useDEFAULT_MAX_FAN_OUT). - extract_
entities - Extract salient entities/keywords from one memory’s text. The result is lowercased and de-duplicated. Two sources:
- extract_
entities_ with_ source extract_entities, keeping track of where each entity came from.- forget_
entities - Drop the entity rows for one memory (used when a memory is invalidated or superseded, so the index does not keep routing traffic to a dead memory).
- incremental_
edges_ for_ memory - Propose
relates_toedges from one freshly written memory to the active memories it shares entities with. - project_
entities - Replace the entity rows for one memory. Pure projection of
text, so it is safe to call on every accept, merge and rebuild. - reproject_
all_ entities - Rebuild
memory_entitiesfor every active memory. Used bykimetsu brain rebuildand by the v11 migration backfill, so an existing brain gets an entity index without waiting for its memories to be rewritten.