Skip to content

feat!: add Tier 1 graph algorithms and honor temporal mode#85

Merged
pdlug merged 2 commits into
mainfrom
feat/graph-algorithms
Apr 19, 2026
Merged

feat!: add Tier 1 graph algorithms and honor temporal mode#85
pdlug merged 2 commits into
mainfrom
feat/graph-algorithms

Conversation

@pdlug
Copy link
Copy Markdown
Contributor

@pdlug pdlug commented Apr 19, 2026

  • Adds store.algorithms.* with shortestPath, reachable, canReach, neighbors, and degree as a lazily-built facade on Store. All traversal algorithms compile to a single recursive-CTE query that shares the dialect's path-tracking primitives with .recursive() and store.subgraph(), so SQLite and PostgreSQL have identical semantics.
  • Threads temporalMode / asOf through every algorithm and through store.subgraph(), defaulting to graph.defaults.temporalMode. Algorithms and subgraph previously used hardcoded filters (algorithms: deleted_at IS NULL; subgraph: effectively "includeEnded") that diverged from store.query() and the collection APIs.
  • Consolidates buildReachableCte into src/store/recursive-cte.ts (shared between algorithms and subgraph), aliases AlgorithmCyclePolicy to RecursiveCyclePolicy, and adds a resolveTemporalOptions helper to collapse duplicated fallback logic across call sites.
  • BREAKING: store.subgraph() now follows graph.defaults.temporalMode (typically "current") instead of hardcoded soft-delete-only filtering. Callers that relied on walking through validity-ended rows must pass temporalMode: "includeEnded" explicitly. Soft-delete handling under the default "current" mode is unchanged.
  • Removes the executeCanReach self-path short-circuit so canReach(a, a) honors the temporal filter and matches shortestPath(a, a) when a isn't visible under the resolved mode.

Docs

  • New /graph-algorithms page with Shared Options table, per-algorithm reference, and a Temporal Behavior section.
  • schemas-stores.md updated for the new subgraph options and algorithm quick-reference.
  • queries/temporal.md cross-references the expanded surface.
  • 14-research-copilot.ts showcase example demonstrating all five algorithms alongside semantic search and ontology-expanded topic matching.

Adds `shortestPath`, `reachable`, `canReach`, `neighbors`, and `degree`
as a lazily-built facade on Store. All traversal algorithms compile to
a single recursive-CTE query that reuses the dialect's existing
path-tracking primitives (`initializePath` / `extendPath` / `cycleCheck`),
so SQLite and PostgreSQL share the same semantics as subgraph extraction
and the recursive query builder.

These cover the high-utility primitives identified in the graph-algorithms
evaluation: recommendations, routing, access control, dependency analysis —
without requiring in-memory graph libraries for small to medium fanout.

Includes the `14-research-copilot.ts` showcase demonstrating all five
algorithms alongside semantic search and ontology-expanded topic matching
over a landmark-ML-papers corpus, plus full docs at `/graph-algorithms`.
@pdlug pdlug force-pushed the feat/graph-algorithms branch from ab7f4bc to 42308ac Compare April 19, 2026 05:18
All `store.algorithms.*` and `store.subgraph()` now accept `temporalMode`
and `asOf` options, defaulting to `graph.defaults.temporalMode`. Both
surfaces were previously hardcoded (algorithms filtered only
`deleted_at IS NULL`; subgraph was effectively `"includeEnded"`), which
left them inconsistent with `store.query()` and collection reads.

Also consolidates the recursive-CTE helper previously duplicated across
subgraph and the algorithms module into a single `src/store/recursive-cte.ts`,
and unifies `AlgorithmCyclePolicy` with `RecursiveCyclePolicy` so both
surfaces share one canonical cycle-policy union.

BREAKING: `store.subgraph()` previously hardcoded soft-delete-only
filtering. It now follows `graph.defaults.temporalMode` (typically
`"current"`). Callers that relied on walking through validity-ended rows
must pass `temporalMode: "includeEnded"` explicitly. Soft-delete handling
is unchanged under the default `"current"` mode, so most callers see no
difference.

- `executeCanReach` self-path short-circuit removed: `canReach(a, a)`
  now flows through the CTE and returns `false` when `a` isn't visible
  under the resolved mode (matches `shortestPath(a, a)`).
- `resolveTemporalOptions(ctx, options)` helper collapses the duplicated
  fallback + conditional-spread pattern at each call site.
- New `TEMPORAL_ANCHORS` test utility shared by algorithms and subgraph
  temporal tests.
@pdlug pdlug force-pushed the feat/graph-algorithms branch from 42308ac to e4936ad Compare April 19, 2026 05:37
@pdlug pdlug merged commit 12055d0 into main Apr 19, 2026
10 checks passed
@pdlug pdlug deleted the feat/graph-algorithms branch April 19, 2026 05:40
@github-actions github-actions Bot mentioned this pull request Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant