Skip to content

feat(memory): graph-aware retrieval with BFS traversal and RRF fusion (#1226)#1250

Merged
bug-ops merged 2 commits intomainfrom
graph-memory-retrieval-1226
Mar 5, 2026
Merged

feat(memory): graph-aware retrieval with BFS traversal and RRF fusion (#1226)#1250
bug-ops merged 2 commits intomainfrom
graph-memory-retrieval-1226

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

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

Summary

Phase 3 of graph memory epic (#1222): graph-aware retrieval with BFS traversal, composite scoring, and context injection.

Closes #1226

  • graph_recall function: fuzzy word-split entity matching (MAX_WORDS=5), depth-tracked BFS expansion (MAX_FRONTIER=300), composite scoring with f32::total_cmp, deduplication
  • bfs_with_depth: extends existing BFS with per-entity hop distance tracking, empty visited guard
  • MemoryRoute::Graph: non-cfg-gated variant with RELATIONSHIP_PATTERNS heuristic ("related to", "thinks about", "preference for", etc.)
  • BudgetAllocation.graph_facts: 4% token budget when graph-memory enabled, redistributed from summaries/semantic/cross_session/code_context (-1% each)
  • recall_graph on SemanticMemory: new graph_store field (cfg-gated), Graph match arm in recall_routed as Hybrid fallback
  • Context injection: [known facts] prefix, fact-by-fact token counting, sanitization via sanitize_memory_message (6th memory path)
  • GraphConfig in MemoryState: runtime access to recall_limit/max_hops from config

Security

  • SQL injection: all queries use bind parameters, LIKE metacharacters escaped
  • Content sanitization: graph facts pass through ContentSanitizer (ExternalUntrusted trust level)
  • Resource exhaustion: MAX_FRONTIER=300 (prevents SQLite 999 bind limit), MAX_WORDS=5 (prevents query amplification)
  • NaN handling: f32::total_cmp for deterministic sort ordering

Test plan

  • cargo +nightly fmt --check
  • cargo clippy --workspace --features full -- -D warnings
  • cargo nextest run --workspace --features full --lib --bins (4189 passed, 11 skipped)
  • graph_recall: empty graph, fuzzy match, max_hops, dedup, sort, truncate, empty words fallback
  • bfs_with_depth: depth tracking via Entry::Vacant API
  • Router: relationship queries -> Graph, "translate" does not false-positive
  • BudgetAllocation: graph_facts=0 when disabled, 4% when enabled
  • Test delta: 3782 -> 4189 (+407 including main merge)

…#1226)

Phase 3 of graph memory epic (#1222): augment existing recall with
graph traversal, scoring, and context injection.

- Add graph_recall function with fuzzy word-split entity matching,
  depth-tracked BFS expansion, composite scoring, and deduplication
- Add bfs_with_depth to GraphStore with MAX_FRONTIER=300 guard
  against SQLite bind variable limit
- Add MemoryRoute::Graph variant with RELATIONSHIP_PATTERNS heuristic
- Add BudgetAllocation.graph_facts (4% when graph-memory enabled)
- Add recall_graph method to SemanticMemory with graph_store field
- Add graph facts context injection with [known facts] prefix,
  fact-by-fact token budget enforcement, and sanitization
- Add GraphConfig to MemoryState for runtime recall_limit/max_hops
- Use f32::total_cmp for NaN-safe composite score sorting
@bug-ops bug-ops enabled auto-merge (squash) March 5, 2026 22:39
@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 5, 2026
@bug-ops bug-ops merged commit 38015eb into main Mar 5, 2026
28 checks passed
@bug-ops bug-ops deleted the graph-memory-retrieval-1226 branch March 5, 2026 23:53
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

Development

Successfully merging this pull request may close these issues.

feat(memory): graph-aware retrieval with BFS traversal and RRF fusion

1 participant