1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! Graph traversal algorithms for relationship-aware retrieval.
//!
//! This module provides BFS, DFS, and shortest path algorithms for exploring
//! the knowledge graph. All algorithms operate on the `LinkStore` trait from
//! khive-db, enabling relationship-aware retrieval pipelines.
//!
//! # Algorithm Selection Guide
//!
//! | Use Case | Algorithm | Function |
//! |----------|-----------|----------|
//! | Explore neighbors | BFS | [`bfs_traverse`] |
//! | Find shortest path | Bidirectional BFS | [`find_shortest_path`] |
//! | Deep exploration | DFS | [`dfs_traverse`] |
//!
//! # Architecture (ADR-004)
//!
//! ```text
//! khive-db khive-retrieval
//! +-----------------+ +----------------------+
//! | LinkStore trait | <--- | Traversal algorithms |
//! | EntityRef, Link | | PathNode, Direction |
//! | StorageContext | | TraversalOptions |
//! +-----------------+ +----------------------+
//! ```
//!
//! # RETRIEVAL-09: Audit Logging for Graph Operations
//!
//! **Current state**: Graph traversal algorithms do NOT emit audit logs.
//!
//! **Design decision**: Audit logging is the responsibility of the caller
//! (typically khive-api or middleware layer), not the retrieval algorithms.
//! This keeps the traversal code focused and testable.
//!
//! **What callers should log**:
//!
//! | Event | Context to Capture |
//! |-------|-------------------|
//! | Traversal start | start_node, direction, max_depth, link_types |
//! | Traversal complete | nodes_visited, paths_found, duration_ms |
//! | Depth limit hit | node_at_limit, depth |
//! | Result limit hit | total_candidates, returned_count |
//!
//! **Future work**: If audit logging moves into the retrieval layer, add
//! a `TraversalObserver` trait for pluggable logging without coupling to
//! a specific logging framework.
//!
//! # Safety Limits
//!
//! All algorithms enforce safety limits to prevent runaway traversals:
//! - [`MAX_TRAVERSAL_DEPTH`]: Maximum hops from start (20)
//! - [`MAX_TRAVERSAL_RESULTS`]: Maximum nodes returned (10,000)
//!
//! # Example
//!
//! ```ignore
//! use khive_retrieval::graph::{bfs_traverse, find_shortest_path, TraversalOptions, Direction};
//! use khive_db::{LinkStore, StorageContext};
//!
//! // BFS exploration
//! let options = TraversalOptions::new(3)
//! .with_direction(Direction::Out)
//! .with_link_types(["contains", "references"]);
//!
//! let neighbors = bfs_traverse(&store, &ctx, start_ref, &options).await?;
//!
//! // Find shortest path
//! if let Some(path) = find_shortest_path(&store, &ctx, from, to, 10).await? {
//! println!("Path length: {} hops", path.len() - 1);
//! }
//! ```
//!
//! See [ADR-004](../docs/ADR-004-graph-traversal.md) for algorithm specification.
/// Helper functions for graph traversal (proximity scoring, neighbor extraction, etc.).
// Re-export compat types (legacy graph API shims)
pub use ;
// Re-export public types
pub use ;
// Re-export direction variants for convenience
pub use ;
// Re-export traversal algorithms
pub use bfs_traverse;
pub use dfs_traverse;
pub use find_shortest_path;