Skip to content

feat(memory): Kumiho belief revision and D-MEM RPE routing for graph memory#2465

Merged
bug-ops merged 1 commit intomainfrom
feat/issue-2441/kumiho-belief-revision-graph-mem
Mar 30, 2026
Merged

feat(memory): Kumiho belief revision and D-MEM RPE routing for graph memory#2465
bug-ops merged 1 commit intomainfrom
feat/issue-2441/kumiho-belief-revision-graph-mem

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 30, 2026

Summary

Changes

  • crates/zeph-memory/src/graph/belief_revision.rs — new BeliefRevisionEngine, contradiction heuristic, 13 tests
  • crates/zeph-memory/src/graph/rpe.rs — new RpeRouter, RPE compute, safety valve, 9 tests
  • crates/zeph-db/migrations/sqlite/056_kumiho_dmem.sql + postgres variant — superseded_by column + index
  • crates/zeph-config/src/memory.rsBeliefRevisionConfig, RpeConfig (nested, matching SpreadingActivationConfig pattern)
  • crates/zeph-memory/src/graph/resolver/mod.rs — belief revision called after edge insert
  • crates/zeph-core/src/agent/persistence.rs — RPE gate before graph extraction spawn

Test plan

  • cargo +nightly fmt --check clean
  • cargo clippy --all-targets --workspace -- -D warnings clean
  • cargo nextest run --workspace --lib --bins — 6805 passed (+27 new tests vs base)
  • Config deserialization validation: similarity_threshold and threshold both annotated with validate_similarity_threshold (rejects NaN/Inf/-1.0)
  • Live session test required before merge (LLM serialization gate — resolver changes)

Closes #2441, closes #2442

@github-actions github-actions bot added documentation Improvements or additions to documentation memory zeph-memory crate (SQLite) rust Rust code changes core zeph-core crate enhancement New feature or request size/XL Extra large PR (500+ lines) labels Mar 30, 2026
…memory

Implements two research features in the MAGMA graph memory subsystem:

**Kumiho AGM-inspired belief revision (#2441)**
- New `BeliefRevisionEngine` in `graph/belief_revision.rs`: detects contradicting
  edges using semantic similarity + relation domain matching (not exact string match)
- Superseded edges receive `valid_to` timestamp and `superseded_by` pointer to the
  new edge, creating an immutable revision audit trail
- Contradiction heuristic: same entity pair + same relation domain + high fact
  similarity (default threshold 0.85) — reinforcing facts are never superseded
- New fact embedded once at insertion; existing edges embedded only for same-domain
  candidates, avoiding the N+1 embedding problem
- Migration 056 adds `superseded_by INTEGER` column and index to graph edges table

**D-MEM RPE-based tiered graph extraction routing (#2442)**
- New `RpeRouter` in `graph/rpe.rs`: gates MAGMA graph extraction with a Reward
  Prediction Error signal computed from embedding similarity to recent context and
  entity novelty ratio
- Low-RPE turns (routine/repeated) skip expensive graph extraction (SQLite-only write)
- High-RPE turns (new entities, belief contradictions) trigger full MAGMA pipeline
- Safety valve: `max_skip_turns` (default 5) forces extraction after N consecutive
  skips regardless of RPE, preventing silent coverage gaps
- RPE state stored in bounded VecDeque (size 10) on MemoryState; cold start returns
  RPE=1.0 (maximum surprise)

Config:
  [memory.graph.belief_revision]  enabled = false, similarity_threshold = 0.85
  [memory.graph.rpe]              enabled = false, threshold = 0.3, max_skip_turns = 5

Both features are disabled by default and add 27 unit tests (6805 total).

Closes #2441, closes #2442
@bug-ops bug-ops force-pushed the feat/issue-2441/kumiho-belief-revision-graph-mem branch from e2914ec to e6be194 Compare March 30, 2026 20:11
@bug-ops bug-ops enabled auto-merge (squash) March 30, 2026 20:12
@bug-ops bug-ops merged commit 7813191 into main Mar 30, 2026
27 checks passed
@bug-ops bug-ops deleted the feat/issue-2441/kumiho-belief-revision-graph-mem branch March 30, 2026 20:18
bug-ops added a commit that referenced this pull request Mar 30, 2026
Each physical connection to sqlite::memory: is a separate empty database.
When the pool size is >1, queries routed to connections other than the one
that ran migrations hit a schema-less DB and fail with
"no such column: superseded_by".

Capping max_connections at 1 for :memory: URLs ensures all queries share
the same migrated schema. Fixes 91 failing graph tests introduced after
migration 056 (superseded_by column) in PR #2465.

Closes #2468
bug-ops added a commit that referenced this pull request Mar 30, 2026
Each physical connection to sqlite::memory: is a separate empty database.
When the pool size is >1, queries routed to connections other than the one
that ran migrations hit a schema-less DB and fail with
"no such column: superseded_by".

Capping max_connections at 1 for :memory: URLs ensures all queries share
the same migrated schema. Fixes 91 failing graph tests introduced after
migration 056 (superseded_by column) in PR #2465.

Closes #2468
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core zeph-core crate documentation Improvements or additions to documentation enhancement New feature or request memory zeph-memory crate (SQLite) rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

1 participant