ruvector/crates/ruvector-dag/examples/basic_usage.rs
Claude d35e5906ab
fix(dag): resolve compilation errors and API mismatches
Fixes across attention mechanisms, SONA engine, and examples:

Attention mechanisms:
- hierarchical_lorentz: Use dag.node_count(), dag.children() API
- parallel_branch: Replace get_children() with children()
- temporal_btsp: Fix node.estimated_cost access, remove selectivity
- cache: Use dag.node_ids() and dag.children() for iteration
- mincut_gated: Fix return type to match DagAttentionMechanism trait
- selector: Update tests to use OperatorNode::new()

SONA/QuDAG:
- sona/engine: Add deprecated Scan/Join match arms
- ml_kem: Fix unused parameter warnings
- ml_dsa: Fix unused parameter warnings

Examples:
- basic_usage: Use dag.children() instead of get_children()
- learning_workflow: Fix HnswScan/Sort field names, trajectory access
- attention_demo: Import DagAttentionMechanism trait
- attention_selection: Fix CausalConeConfig field names
- self_healing: Remove non-existent result fields
- federated_coherence: Add parentheses for comparison expression

Cargo.toml:
- Register all exotic examples with explicit paths

All 12 examples now build and run successfully.
2025-12-30 01:50:51 +00:00

73 lines
2.1 KiB
Rust

//! Basic usage example for Neural DAG Learning
use ruvector_dag::dag::{QueryDag, OperatorNode, OperatorType};
fn main() {
println!("=== Neural DAG Learning - Basic Usage ===\n");
// Create a new DAG
let mut dag = QueryDag::new();
// Add nodes representing query operators
println!("Building query DAG...");
let scan = dag.add_node(OperatorNode::seq_scan(0, "users"));
println!(" Added SeqScan on 'users' (id: {})", scan);
let filter = dag.add_node(OperatorNode::filter(1, "age > 18"));
println!(" Added Filter 'age > 18' (id: {})", filter);
let sort = dag.add_node(OperatorNode::sort(2, vec!["name".to_string()]));
println!(" Added Sort by 'name' (id: {})", sort);
let limit = dag.add_node(OperatorNode::limit(3, 10));
println!(" Added Limit 10 (id: {})", limit);
let result = dag.add_node(OperatorNode::new(4, OperatorType::Result));
println!(" Added Result (id: {})", result);
// Connect nodes
dag.add_edge(scan, filter).unwrap();
dag.add_edge(filter, sort).unwrap();
dag.add_edge(sort, limit).unwrap();
dag.add_edge(limit, result).unwrap();
println!("\nDAG Statistics:");
println!(" Nodes: {}", dag.node_count());
println!(" Edges: {}", dag.edge_count());
// Compute topological order
let order = dag.topological_sort().unwrap();
println!("\nTopological Order: {:?}", order);
// Compute depths
let depths = dag.compute_depths();
println!("\nNode Depths:");
for (id, depth) in &depths {
println!(" Node {}: depth {}", id, depth);
}
// Get children
println!("\nNode Children:");
for node_id in 0..5 {
let children = dag.children(node_id);
println!(" Node {}: {:?}", node_id, children);
}
// Demonstrate iterators
println!("\nDFS Traversal:");
for (i, node_id) in dag.dfs_iter(scan).enumerate() {
if i < 10 {
println!(" Visit: {}", node_id);
}
}
println!("\nBFS Traversal:");
for (i, node_id) in dag.bfs_iter(scan).enumerate() {
if i < 10 {
println!(" Visit: {}", node_id);
}
}
println!("\n=== Example Complete ===");
}