Skip to content

feat(core,py): kind-filtered bfs and shortest_path traversal — 2.3.0 / 0.2.0#4

Merged
oldnordic merged 2 commits into
mainfrom
feat/bfs-shortest-path-filtered
May 15, 2026
Merged

feat(core,py): kind-filtered bfs and shortest_path traversal — 2.3.0 / 0.2.0#4
oldnordic merged 2 commits into
mainfrom
feat/bfs-shortest-path-filtered

Conversation

@oldnordic
Copy link
Copy Markdown
Owner

Summary

  • Adds bfs_filtered and shortest_path_filtered to GraphBackend and the underlying free functions in bfs.rs, mirroring the existing k_hop_filtered surface.
  • Exposes the new filters in the Python binding via additive edge_types / direction kwargs on bfs, shortest_path, and k_hop — all backwards-compatible (kwargless calls produce identical results).
  • Bumps sqlitegraph-core 2.2.5 → 2.3.0 and sqlitegraph-py 0.1.1 → 0.2.0 (SemVer minor: additive public surface, no breakage).

Downstream consumers (e.g. grounded-graph) overlay multiple relationship kinds (call, imports, defines, tests) on the same node pair, and callers(X) queries need to follow only call-style edges. Today they can use neighbors(edge_type=...) for 1-hop, but bfs/shortest_path had no equivalent — this PR closes that gap.

Implementation notes

  • multi_hop::typed_adjacency and multi_hop::build_lookup are now pub(crate) so bfs.rs reuses the typed-edge SQL path that already backs k_hop_filtered. No duplicated SQL constants.
  • SqliteGraphBackend implements both new trait methods via the new free functions.
  • V3Backend stubs both, matching the existing k_hop_filtered delegation. V3 typed-edge BFS is already known unfinished; tracked alongside that TODO.
  • Python: extends existing bfs/shortest_path/k_hop signatures with optional edge_types / direction kwargs that dispatch to the new *_filtered trait methods. Empty-list semantics match the trait contract (bfs/k_hop → empty result, shortest_pathNone).

Test plan

  • cargo fmt --all --check — clean
  • RUSTFLAGS="-D warnings" cargo check --lib --bins — clean
  • cargo test -p sqlitegraph --lib -- --test-threads=1 — 1161 passed, 0 failed
  • cargo test -p sqlitegraph --test bfs_tests — 16 passed (8 existing + 8 new filtered tests)
  • cargo test -p sqlitegraph --test integration_tests --test cache_effectiveness_tests --test snapshot_isolation_tests --test query_cache_tests --test v3_reopen_durability --test sqlite_reopen_tests — all green
  • PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 maturin develop --release && pytest tests/ — 51 passed (40 existing + 11 new filtered-traversal tests)
  • Pre-existing doc_tests.rs failures (README missing 5 sections) are not introduced by this PR and are not run by CI's cargo test (lib) step.

🤖 Generated with Claude Code

oldnordic and others added 2 commits May 15, 2026 23:36
Mirrors the existing k_hop_filtered surface so callers can restrict
breadth-first traversal and shortest-path queries to a subset of edge
types — needed by downstream graph tools that overlay multiple
relationship kinds (calls, imports, defines, tests) on the same node
pair and want, for example, "callers of X" to follow only call edges.

Core (sqlitegraph-core):
- bfs::bfs_neighbors_filtered and bfs::shortest_path_filtered free
  functions, reusing multi_hop::typed_adjacency (now pub(crate)) so the
  typed-edge SQL path is shared with k_hop_filtered. Empty
  allowed_edge_types returns an empty result for bfs (matches
  k_hop_filtered) and None for shortest_path.
- GraphBackend::bfs_filtered and GraphBackend::shortest_path_filtered
  trait methods plus &B blanket forwarders.
- SqliteGraphBackend implements both via the new free functions.
- V3Backend stubs both, matching the existing k_hop_filtered
  delegation; full V3 wiring tracked alongside that TODO.

Python (sqlitegraph-py):
- bfs(start, depth, edge_types=None, direction=None) — when
  edge_types is provided, dispatches to bfs_filtered with the given
  direction; otherwise behavior is unchanged.
- shortest_path(start, end, edge_types=None) — optional kwarg
  dispatches to shortest_path_filtered.
- k_hop(start, depth, direction=None, edge_types=None) — optional
  edge_types dispatches to the existing k_hop_filtered, closing the
  Python-side gap.

Tests:
- 8 Rust integration tests in bfs_tests.rs covering single-kind
  restriction, union over multiple kinds, empty-allowlist semantics,
  incoming direction, path selection through the allowed kind,
  excluded-kind paths returning None, and same-node singleton.
- 11 Python pytest cases in test_filtered_traversal.py covering each
  new kwarg plus backwards-compatibility for the old kwargless calls.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- sqlitegraph-core: 2.2.5 → 2.3.0 (new public surface,
  bfs_filtered/shortest_path_filtered trait methods and free functions,
  SemVer minor)
- sqlitegraph-py:   0.1.1 → 0.2.0 (new edge_types kwargs on bfs,
  shortest_path, and k_hop; SemVer minor for additive Python surface)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@oldnordic oldnordic merged commit f70699b into main May 15, 2026
10 checks passed
@oldnordic oldnordic deleted the feat/bfs-shortest-path-filtered branch May 15, 2026 21:46
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