Summary
Phase 3 of graph memory (#1222): augment existing recall with graph traversal, scoring, and RRF fusion.
Depends on: #1225 (extraction pipeline)
Tasks
1. Graph Retrieval (graph/retrieval.rs)
graph_recall(query: &str, store: &GraphStore, qdrant: &EmbeddingStore, provider: &AnyProvider, config: &GraphConfig) -> Result<Vec<GraphFact>>:
- Entity matching: Embed query → search
zeph_graph_entities Qdrant collection (top-5 entities by cosine). Also run SQLite fuzzy match as fallback.
- BFS expansion: For each matched entity, run
store.bfs(entity_id, config.max_hops) to collect neighbors + edges.
- Scoring: For each collected edge, compute
GraphFact.composite_score() = entity_match_score * (1/(1+hop_distance)) * confidence.
- Dedup: Remove duplicate edges (same source+target+relation).
- Rank and truncate: Sort by composite_score desc, take top
config.recall_limit.
2. Router Update
Add Graph variant to MemoryRoute enum (always present, not cfg-gated). Router only returns Graph when graph-memory feature is enabled. When disabled, Graph route is treated as Hybrid.
Update HeuristicRouter:
- "What does the user think about X?" → Graph route
- "How is X related to Y?" → Graph route
- Entity-centric queries (contains known entity name) → Graph route
3. Context Budget
Add graph_facts field to BudgetAllocation (always present, 0 when disabled):
- Redistribute: code_context 30% → 29%, graph_facts 0% → 4% (only when enabled)
- Existing allocations: summaries=8%, semantic_recall=8%, cross_session=4%, recent_history=50%
4. Context Formatting
Format graph facts as a system message with GRAPH_FACTS_PREFIX:
## Known Facts
- User prefers neovim for Rust development (since 2026-01) [confidence: 0.95]
- User works on project "zeph" (AI agent) [confidence: 1.0]
Architecture Reference
See .local/plan/graph-memory-architecture.md Section 5 for retrieval pseudocode, router patterns, and budget allocation.
Acceptance Criteria
Summary
Phase 3 of graph memory (#1222): augment existing recall with graph traversal, scoring, and RRF fusion.
Depends on: #1225 (extraction pipeline)
Tasks
1. Graph Retrieval (graph/retrieval.rs)
graph_recall(query: &str, store: &GraphStore, qdrant: &EmbeddingStore, provider: &AnyProvider, config: &GraphConfig) -> Result<Vec<GraphFact>>:zeph_graph_entitiesQdrant collection (top-5 entities by cosine). Also run SQLite fuzzy match as fallback.store.bfs(entity_id, config.max_hops)to collect neighbors + edges.GraphFact.composite_score()= entity_match_score * (1/(1+hop_distance)) * confidence.config.recall_limit.2. Router Update
Add
Graphvariant toMemoryRouteenum (always present, not cfg-gated). Router only returnsGraphwhengraph-memoryfeature is enabled. When disabled,Graphroute is treated asHybrid.Update
HeuristicRouter:3. Context Budget
Add
graph_factsfield toBudgetAllocation(always present, 0 when disabled):4. Context Formatting
Format graph facts as a system message with
GRAPH_FACTS_PREFIX:Architecture Reference
See
.local/plan/graph-memory-architecture.mdSection 5 for retrieval pseudocode, router patterns, and budget allocation.Acceptance Criteria