Skip to content

retrieval_astar: O(seeds × all_nodes) A* loop has no node-count cap #4368

@bug-ops

Description

@bug-ops

Description

graph_recall_astar in crates/zeph-memory/src/graph/retrieval_astar.rs runs an A* search from every seed entity to every other node in the in-memory graph (lines 257–283). With limit seeds and N BFS-reachable nodes the complexity is O(limit × N × E log N) where E is the edge count per hop. No cap is applied to node_map size.

Actual Behavior

For a populated graph with many entities and max_hops = 2, the inner loop over node_map.values() can grow large. The spreading-activation path (activation.rs) caps activated nodes at 5; the A* path has no analogous guard.

Expected Behavior

Add a MAX_GRAPH_NODES constant (e.g. 500) and truncate node_map to the highest-scored nodes before the A* loop, consistent with how spreading-activation guards itself.

Environment

  • HEAD: 9d76476
  • File: crates/zeph-memory/src/graph/retrieval_astar.rs:257-283

Metadata

Metadata

Assignees

Labels

P3Research — medium-high complexityenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions