Skip to content

Commit 3fffd0b

Browse files
authored
docs: document KG supersede usage (#2059)
* docs: document KG supersede usage Requested-by: Grace Gettert <grace.gettert@carpe.io> * docs: update recall skills for KG supersede Requested-by: Grace Gettert <grace.gettert@carpe.io> * docs: update Claude recall skill supersede guidance Requested-by: Grace Gettert <grace.gettert@carpe.io>
1 parent 368972e commit 3fffd0b

8 files changed

Lines changed: 106 additions & 14 deletions

File tree

.antigravity-plugin/skills/mempalace-recall/SKILL.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ and violates MemPalace's "memory should feel instant" budget.
6565
5. **After a substantive session**, record continuity with
6666
`mempalace_diary_write` (background hooks may already do this — do not
6767
double-file).
68-
6. **When a fact changes**, call `mempalace_kg_invalidate` on the old
69-
fact, then `mempalace_kg_add` for the new one.
68+
6. **When a fact changes**, choose the operation that preserves temporal
69+
history: use `mempalace_kg_supersede` for single-valued replacements
70+
(model, employer, owner, address, current status),
71+
`mempalace_kg_invalidate` for facts that ended without replacement,
72+
and `mempalace_kg_add` for independent/coexisting facts.
7073

7174
The full canonical protocol — shared verbatim with the Antigravity
7275
recall rule and the other integrations — lives in
@@ -78,6 +81,7 @@ recall rule and the other integrations — lives in
7881
|---|---|
7982
| Find any memory by meaning | `mempalace_search` (start here) |
8083
| Relational / time-bound facts about an entity | `mempalace_kg_query` |
84+
| Replace a single-valued fact | `mempalace_kg_supersede` |
8185
| The chronological story of an entity | `mempalace_kg_timeline` |
8286
| Recent session continuity | `mempalace_diary_read` |
8387
| Which wings / rooms exist (scope unknown) | `mempalace_list_wings`, `mempalace_list_rooms` |
@@ -97,8 +101,9 @@ question — not a system prompt or pasted conversation) plus optional
97101
installer `hooks/antigravity/install.sh`). Do not silently fall back
98102
to guessing from model memory.
99103
- **Stale or conflicting facts.** Prefer the knowledge graph's
100-
time-valid answer; if a fact has changed, invalidate the old one and
101-
add the new one rather than overwriting context silently.
104+
time-valid answer. Use `mempalace_kg_supersede` for single-valued replacements,
105+
`mempalace_kg_invalidate` for facts that ended without replacement,
106+
and `mempalace_kg_add` for independent/coexisting facts.
102107

103108
## Anti-patterns — never do these
104109

.claude-plugin/skills/mempalace-recall/SKILL.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ a variable, fixing a typo). Recall is question-driven, not reflexive.
4444
stored content.
4545
4. After a substantive session, record continuity with
4646
`mempalace_diary_write` (skip if a background hook already saved).
47-
5. When a fact changes: `mempalace_kg_invalidate` the old fact, then
48-
`mempalace_kg_add` the new one.
47+
5. When a fact changes: use `mempalace_kg_supersede` for
48+
single-valued replacements, `mempalace_kg_invalidate` for facts that
49+
ended without replacement, and `mempalace_kg_add` for
50+
independent/coexisting facts.
4951

5052
## Unhappy paths
5153

@@ -61,7 +63,9 @@ a variable, fixing a typo). Recall is question-driven, not reflexive.
6163
--archive-existing --yes`), not re-mine, which drops MCP-added drawers
6264
and diary entries (#1843). Do not repair in-process.
6365
- **Conflicting facts** — trust the knowledge graph's time-valid answer;
64-
invalidate-then-add rather than overwriting silently.
66+
use `mempalace_kg_supersede` for single-valued replacements,
67+
`mempalace_kg_invalidate` for facts that ended without replacement,
68+
and `mempalace_kg_add` for independent/coexisting facts.
6569

6670
The canonical protocol, shared across all MemPalace integrations, lives
6771
in `integrations/shared/recall-protocol.md`.

integrations/shared/recall-protocol.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,19 @@ question-driven, not reflexive.
4141
5. **After a substantive session**, record continuity with
4242
`mempalace_diary_write` (background hooks may already do this — do not
4343
double-file).
44-
6. **When a fact changes**, call `mempalace_kg_invalidate` on the old
45-
fact, then `mempalace_kg_add` for the new one.
44+
6. **When a fact changes**, choose the operation that preserves temporal
45+
history: use `mempalace_kg_supersede` for single-valued replacements
46+
(model, employer, owner, address, current status),
47+
`mempalace_kg_invalidate` for facts that ended without replacement,
48+
and `mempalace_kg_add` for independent/coexisting facts.
4649

4750
## Tool selection
4851

4952
| You need | Tool |
5053
|---|---|
5154
| Find any memory by meaning | `mempalace_search` (start here) |
5255
| Relational / time-bound facts about an entity | `mempalace_kg_query` |
56+
| Replace a single-valued fact | `mempalace_kg_supersede` |
5357
| The chronological story of an entity | `mempalace_kg_timeline` |
5458
| Recent session continuity | `mempalace_diary_read` |
5559
| Which wings / rooms exist (when scope unknown) | `mempalace_list_wings`, `mempalace_list_rooms` |
@@ -75,8 +79,9 @@ question — not a system prompt or pasted conversation) plus optional
7579
by re-mining. See "Recovering a corrupt index" below. Do not attempt an
7680
in-process repair from the agent; guide the user to run the CLI.
7781
- **Stale or conflicting facts.** Prefer the knowledge graph's
78-
time-valid answer; if a fact has changed, invalidate the old one and
79-
add the new one rather than overwriting context silently.
82+
time-valid answer. Use `mempalace_kg_supersede` for single-valued replacements,
83+
`mempalace_kg_invalidate` for facts that ended without replacement,
84+
and `mempalace_kg_add` for independent/coexisting facts.
8085

8186
## Recovering a corrupt index
8287

skills/mempalace-recall/SKILL.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ and violates MemPalace's "memory should feel instant" budget.
6060
stored content — quoting the exact words is the point of the system.
6161
5. After a substantive session, record continuity with
6262
`mempalace_diary_write` (skip if a background hook already saved).
63-
6. When a fact changes: `mempalace_kg_invalidate` the old fact, then
64-
`mempalace_kg_add` the new one.
63+
6. When a fact changes: use `mempalace_kg_supersede` for
64+
single-valued replacements, `mempalace_kg_invalidate` for facts that
65+
ended without replacement, and `mempalace_kg_add` for
66+
independent/coexisting facts.
6567

6668
The full canonical protocol — shared verbatim with the Cursor recall
6769
rule and the other integrations — lives in
@@ -73,6 +75,7 @@ rule and the other integrations — lives in
7375
|---|---|
7476
| Find any memory by meaning | `mempalace_search` (start here) |
7577
| Relational / time-bound facts about an entity | `mempalace_kg_query` |
78+
| Replace a single-valued fact | `mempalace_kg_supersede` |
7679
| The chronological story of an entity | `mempalace_kg_timeline` |
7780
| Recent session continuity | `mempalace_diary_read` |
7881
| Which wings / rooms exist (scope unknown) | `mempalace_list_wings`, `mempalace_list_rooms` |
@@ -112,7 +115,9 @@ search. The canonical protocol lives in
112115
Do not attempt an in-process repair from the agent. Full steps are in
113116
the shared protocol's "Recovering a corrupt index" section.
114117
- **Conflicting facts.** Trust the knowledge graph's time-valid answer;
115-
invalidate-then-add rather than overwriting silently.
118+
use `mempalace_kg_supersede` for single-valued replacements,
119+
`mempalace_kg_invalidate` for facts that ended without replacement,
120+
and `mempalace_kg_add` for independent/coexisting facts.
116121

117122
## Anti-patterns — never do these
118123

website/concepts/knowledge-graph.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Subject → Predicate → Object [valid_from → valid_to]
1111
```
1212

1313
Facts have time windows. When something stops being true, you invalidate it — and historical queries still find it.
14+
When a single-valued fact changes, supersede it so the old and new values meet at one precise boundary.
1415

1516
## Usage
1617

@@ -49,6 +50,28 @@ kg.invalidate("Kai", "works_on", "Orion", ended="2026-03-01")
4950

5051
Now queries for Kai's current work won't return Orion. Historical queries still will.
5152

53+
### Superseding Facts
54+
55+
When a single-valued fact changes, use `supersede()` instead of hand-rolling `invalidate()` plus `add_triple()`:
56+
57+
```python
58+
kg.add_triple("Kai", "uses_model", "gpt-4.1", valid_from="2026-01-01")
59+
60+
kg.supersede(
61+
"Kai",
62+
"uses_model",
63+
old_obj="gpt-4.1",
64+
new_obj="gpt-5.6",
65+
at="2026-07-20",
66+
)
67+
```
68+
69+
`supersede()` closes the old fact and opens the new one in a single transaction with the same precise boundary.
70+
A query at the handoff returns only the successor, not both values.
71+
72+
Use it for relationships that should have one current value, such as `uses_model`, `works_at`, or `lives_at`.
73+
Keep `invalidate()` for facts that simply ended, and use `add_triple()` for facts that can coexist.
74+
5275
### MCP Tools
5376

5477
Through the MCP server, the knowledge graph is available as tools:
@@ -58,6 +81,7 @@ Through the MCP server, the knowledge graph is available as tools:
5881
| `mempalace_kg_query` | Query entity relationships with time filtering |
5982
| `mempalace_kg_add` | Add facts |
6083
| `mempalace_kg_invalidate` | Mark facts as ended |
84+
| `mempalace_kg_supersede` | Atomically replace one current fact with another |
6185
| `mempalace_kg_timeline` | Chronological entity story |
6286
| `mempalace_kg_stats` | Graph overview |
6387

website/guide/mcp-integration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ This protocol is what turns storage into memory — the AI knows to verify befor
9191
| `mempalace_kg_query` | Entity relationships with time filtering |
9292
| `mempalace_kg_add` | Add facts |
9393
| `mempalace_kg_invalidate` | Mark facts as ended |
94+
| `mempalace_kg_supersede` | Atomically replace one current fact with another |
9495
| `mempalace_kg_timeline` | Chronological entity story |
9596
| `mempalace_kg_stats` | Graph overview |
9697

website/reference/api-reference.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ Default path: `~/.mempalace/knowledge_graph.sqlite3`
128128
| `add_entity(name, entity_type='unknown', properties=None)` | Name, type, props dict | `str` (entity ID) | Add or update entity node |
129129
| `add_triple(subject, predicate, obj, valid_from, valid_to, confidence, source_closet, source_file)` | See below | `str` (triple ID) | Add relationship triple |
130130
| `invalidate(subject, predicate, obj, ended=None)` | Entity names, end date || Mark relationship as ended |
131+
| `supersede(...)` | Entity names, replacement value, optional boundary | `str` (new triple ID) | Atomically replace one current relationship with another |
131132

132133
**`add_triple` parameters:**
133134

@@ -142,6 +143,42 @@ Default path: `~/.mempalace/knowledge_graph.sqlite3`
142143
| `source_closet` | `str` | `None` | Link to verbatim memory |
143144
| `source_file` | `str` | `None` | Original source file |
144145

146+
**`supersede` signature:**
147+
148+
```python
149+
supersede(
150+
subject,
151+
predicate,
152+
old_obj,
153+
new_obj,
154+
at=None,
155+
confidence=1.0,
156+
source_closet=None,
157+
source_file=None,
158+
source_drawer_id=None,
159+
adapter_name=None,
160+
)
161+
```
162+
163+
**`supersede` parameters:**
164+
165+
| Parameter | Type | Default | Description |
166+
|-----------|------|---------|-------------|
167+
| `subject` | `str` || Source entity name |
168+
| `predicate` | `str` || Single-valued relationship type |
169+
| `old_obj` | `str` || Current value to close if it is open |
170+
| `new_obj` | `str` || Replacement value to open |
171+
| `at` | `str` | current UTC instant | Handoff boundary; date-only values normalize to midnight UTC |
172+
| `confidence` | `float` | `1.0` | Confidence score 0.0–1.0 |
173+
| `source_closet` | `str` | `None` | Link to verbatim memory |
174+
| `source_file` | `str` | `None` | Original source file |
175+
| `source_drawer_id` | `str` | `None` | Source drawer provenance |
176+
| `adapter_name` | `str` | `None` | Source adapter provenance |
177+
178+
Use `supersede` when a single-valued relationship changes, such as a model, employer, address, or primary assignment.
179+
It closes the old fact and opens the new fact at the same precise boundary, so an as-of query at the handoff returns only the successor.
180+
Use `invalidate` for facts that simply ended, and `add_triple` for facts that can coexist.
181+
145182
#### Query Methods
146183

147184
| Method | Parameters | Returns |

website/reference/python-api.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ kg = KnowledgeGraph() # uses default path: ~/.mempalace/knowledge_graph.sqlite3
6161
kg.add_entity("Kai", entity_type="person")
6262
kg.add_triple("Kai", "works_on", "Orion", valid_from="2025-06-01")
6363
kg.invalidate("Kai", "works_on", "Orion", ended="2026-03-01")
64+
kg.add_triple("Kai", "uses_model", "gpt-4.1", valid_from="2026-01-01")
65+
kg.supersede(
66+
"Kai",
67+
"uses_model",
68+
old_obj="gpt-4.1",
69+
new_obj="gpt-5.6",
70+
at="2026-07-20",
71+
)
6472

6573
# Read
6674
facts = kg.query_entity("Kai", as_of="2026-01-15", direction="both")
@@ -69,6 +77,9 @@ timeline = kg.timeline("Orion")
6977
stats = kg.stats()
7078
```
7179

80+
Use `supersede()` when a single-valued fact changes.
81+
It writes the old fact's `valid_to` and the new fact's `valid_from` at the same boundary, avoiding overlapping values at the handoff.
82+
7283
## Palace Graph
7384

7485
Room-based navigation graph built from ChromaDB metadata.

0 commit comments

Comments
 (0)