Skip to content

feat(memory): community detection with label propagation and graph eviction (#1228)#1271

Merged
bug-ops merged 4 commits intomainfrom
community-detection
Mar 6, 2026
Merged

feat(memory): community detection with label propagation and graph eviction (#1228)#1271
bug-ops merged 4 commits intomainfrom
community-detection

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

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

Summary

Implements Phase 5 of the graph-based knowledge memory epic (#1222): community detection, graph eviction, and community refresh metrics.

  • Community detection via label propagation (petgraph::UnGraph): groups entities into clusters (max 50 iterations, tie-break by smallest label, min 2 entities), generates LLM summaries, persists to graph_communities
  • Incremental community assignment: new entities placed in nearest community by neighbor majority vote
  • Graph eviction: deletes expired edges older than expired_edge_retention_days, orphan entities with no active edges, enforces optional max_entities cap — runs during community refresh cycle
  • Atomic extraction counter via graph_metadata SQLite table (INSERT ON CONFLICT DO UPDATE)
  • Prompt injection protection: scrub_content() applied to entity names and facts before LLM prompt
  • Community detection failure metric: graph_community_detection_failures in MetricsSnapshot
  • New GraphConfig fields: expired_edge_retention_days (default 90), max_entities (default 0)
  • petgraph = "0.8" added as optional workspace dependency, gated behind graph-memory feature

Test plan

  • 4300 tests pass (cargo nextest run --workspace --features full --lib --bins)
  • 14 new tests: label propagation (12-entity graph, 4 clusters), single-entity filter, all-isolated-nodes, incremental assignment, eviction (expired edges, orphan entities), extraction counter (same-instance and cross-instance persistence via tempfile SQLite)

Follow-up issues filed

Closes #1228

bug-ops added 2 commits March 6, 2026 03:58
…cs (#1228)

- Label Propagation Algorithm (50 iterations, tie-break by min label) via petgraph
- Full-rebuild community upsert with ON CONFLICT(name) and label_index suffix to prevent collisions
- scrub_content() inline sanitizer strips newlines and ASCII control chars from entity names and facts
- run_graph_eviction: expired edge deletion, orphan entity pruning, LRU entity cap
- GraphConfig: expired_edge_retention_days (default 90) and max_entities fields
- community_refresh_interval triggers detection every N extractions in spawn_graph_extraction
- graph_community_detection_failures counter in MetricsSnapshot via Arc<AtomicU64> in SemanticMemory
- 11 unit tests: label propagation clusters, isolated nodes, persistence, extraction count
@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 dependencies Dependency updates enhancement New feature or request size/XL Extra large PR (500+ lines) labels Mar 6, 2026
- Resolve CHANGELOG.md: keep Phase 5 entries + main's aggregator/FTS5/canonicalization entries
- Resolve docs/graph-memory.md: keep Community Detection + Graph Eviction sections, add FTS5 section from main
- Resolve zeph-memory/README.md: merge graph module description (canonicalization + community detection)
- Update upsert_entity calls in community.rs and store.rs tests to include canonical_name parameter (added in main via #1231)
- Regenerate config default snapshot
@bug-ops bug-ops enabled auto-merge (squash) March 6, 2026 03:20
@bug-ops bug-ops merged commit 44e5a5f into main Mar 6, 2026
28 checks passed
@bug-ops bug-ops deleted the community-detection branch March 6, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core zeph-core crate dependencies Dependency updates 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

Development

Successfully merging this pull request may close these issues.

feat(memory): community detection with label propagation

1 participant