feat(core,py): kind-filtered bfs and shortest_path traversal — 2.3.0 / 0.2.0#4
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
bfs_filteredandshortest_path_filteredtoGraphBackendand the underlying free functions inbfs.rs, mirroring the existingk_hop_filteredsurface.edge_types/directionkwargs onbfs,shortest_path, andk_hop— all backwards-compatible (kwargless calls produce identical results).sqlitegraph-core2.2.5 → 2.3.0 andsqlitegraph-py0.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, andcallers(X)queries need to follow only call-style edges. Today they can useneighbors(edge_type=...)for 1-hop, butbfs/shortest_pathhad no equivalent — this PR closes that gap.Implementation notes
multi_hop::typed_adjacencyandmulti_hop::build_lookupare nowpub(crate)sobfs.rsreuses the typed-edge SQL path that already backsk_hop_filtered. No duplicated SQL constants.SqliteGraphBackendimplements both new trait methods via the new free functions.V3Backendstubs both, matching the existingk_hop_filtereddelegation. V3 typed-edge BFS is already known unfinished; tracked alongside that TODO.bfs/shortest_path/k_hopsignatures with optionaledge_types/directionkwargs that dispatch to the new*_filteredtrait methods. Empty-list semantics match the trait contract (bfs/k_hop→ empty result,shortest_path→None).Test plan
cargo fmt --all --check— cleanRUSTFLAGS="-D warnings" cargo check --lib --bins— cleancargo test -p sqlitegraph --lib -- --test-threads=1— 1161 passed, 0 failedcargo 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 greenPYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 maturin develop --release && pytest tests/— 51 passed (40 existing + 11 new filtered-traversal tests)doc_tests.rsfailures (README missing 5 sections) are not introduced by this PR and are not run by CI'scargo test (lib)step.🤖 Generated with Claude Code