Skip to content

[upstream PR 893] Serve graph reads from side-indexes instead of full enumeration #400

@wbugitlab1

Description

@wbugitlab1

Source: Source pull request number: 893 in rohitg00/agentmemory (URL omitted to avoid GitHub cross-reference)
Title: Serve graph reads from side-indexes instead of full enumeration
Author: rohitg00
State: open
Draft: no
Merged: no
Head: rohitg00/agentmemory:fix/graph-read-path-indexes @ e2608e3
Base: main @ 25e7701
Labels: (none)
Changed files: 0
Commits: 0
Created: 2026-06-10T22:49:05Z
Updated: 2026-06-10T23:09:06Z
Closed: (not closed)
Merged at: (not merged)

Original PR body:

Closes #828.

state::list over the graph scopes blocks the worker event loop past ~25K nodes, so every read path that enumerated mem:graph:nodes and mem:graph:edges (searchByEntities, expandFromChunks, temporalQuery, graph-query query/startNodeId) was a worker-killer at scale. The earlier side-index work fixed the write paths and stats; this finishes the read paths.

New side-indexes in src/state/graph-indexes.ts: a 64-shard name catalog read as bounded gets with exact substring semantics, a per-node adjacency index bounding traversal by degree x depth (BFS capped at 5000 visited nodes with an explicit truncated warning), an obsId to nodeId index for chunk expansion, and a readiness marker. Marker absent means readers fall back to the previous enumeration, never silently empty. Writes are hints only; readers verify every hit against the live record (stale flag plus snapshot resetAt), so cascades and wipes need no index cleanup. The marker is set by boot backfill (gated on snapshot totalNodes <= 25K), graph-snapshot-rebuild, and graph-reset, which also clears the name shards so post-reset retrieval stops surfacing pre-reset rows.

Parity tests compare index and enumeration paths on identical graphs for all four read paths, plus fallback, post-rebuild maintenance, and post-reset cases.

Summary by CodeRabbit

  • New Features

    • Added graph read-side indexes to accelerate searches and traversals.
    • Graph queries now preferentially use indexes when available, with automatic fallback to enumeration.
  • Improvements

    • Graph operations (import, export, extraction, sync, snapshot restore) automatically maintain index consistency.
    • Entity searches and temporal queries now leverage indexed lookups for better performance.
    • Traversal operations are bounded to prevent excessive resource consumption.
  • Tests

    • Added parity tests validating indexed and enumeration-based graph operations produce equivalent results.

Local branch:
Fork PR:
Fork decision:
Verification:
Notes:

Metadata

Metadata

Assignees

No one assigned

    Labels

    decision-candidateFork decision has not been madeupstream-openUpstream pull request is openupstream-prTracks an upstream pull request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions