RuVector DAG - Neural Self-Learning DAG
Make your queries faster automatically. RuVector DAG learns from every query execution and continuously optimizes performance—no manual tuning required.
What is This?
RuVector DAG is a self-learning query optimization system. Think of it as a "nervous system" for your database queries that:
- Watches how queries execute and identifies bottlenecks
- Learns which optimization strategies work best for different query patterns
- Adapts in real-time, switching strategies when conditions change
- Heals itself by detecting anomalies and fixing problems before they impact users
Unlike traditional query optimizers that use static rules, RuVector DAG learns from actual execution patterns and gets smarter over time.
Who Should Use This?
| Use Case | Why RuVector DAG Helps |
|---|---|
| Vector Search Applications | Optimize similarity searches that traditional databases struggle with |
| High-Traffic APIs | Automatically adapt to changing query patterns throughout the day |
| Real-Time Analytics | Learn which aggregation paths are fastest for your specific data |
| Edge/Embedded Systems | 58KB WASM build runs in browsers and IoT devices |
| Multi-Tenant Platforms | Learn per-tenant query patterns without manual per-tenant tuning |
Key Benefits
Automatic Performance Improvement
Queries get faster over time without any code changes. In benchmarks, repeated queries show 50-80% latency reduction after the system learns optimal execution paths.
Zero-Downtime Adaptation
When query patterns change (new features, traffic spikes, data growth), the system adapts automatically. No need to rebuild indexes or rewrite queries.
Predictive Problem Prevention
The system detects rising "tension" (early warning signs of bottlenecks) and intervenes before users experience slowdowns.
Works Everywhere
- PostgreSQL via the ruvector-postgres extension
- Browsers via 58KB WASM module
- Embedded systems with minimal memory footprint
- Distributed systems with quantum-resistant sync between nodes
How It Works (Simple Version)
Query comes in → DAG analyzes execution plan → Best attention mechanism selected
↓
Query executes → Results returned → Learning system records what worked
↓
Next similar query benefits from learned optimizations
The system maintains a "MinCut tension" score that acts as a health indicator. When tension rises, the system automatically switches to more aggressive optimization strategies and triggers predictive healing.
Features
- 7 DAG Attention Mechanisms: Topological, Causal Cone, Critical Path, MinCut Gated, Hierarchical Lorentz, Parallel Branch, Temporal BTSP
- SONA Learning: Self-Optimizing Neural Architecture with MicroLoRA adaptation (<100μs)
- Subpolynomial MinCut: O(n^0.12) bottleneck detection—the coherence boundary everything listens to
- Self-Healing: Autonomous anomaly detection, reactive repair, and predictive intervention
- QuDAG Integration: Quantum-resistant distributed pattern learning with bounded sync
- WASM Target: 58KB gzipped for browser and embedded systems
Design Philosophy
MinCut is not an optimization trick here. It is the coherence boundary that everything else listens to. Attention mechanisms, SONA learning, and self-healing all respond to MinCut stress signals—creating a unified nervous system for query optimization.
Quick Start
use ;
use ;
// Build a query DAG
let mut dag = new;
let scan = dag.add_node;
let filter = dag.add_node;
let result = dag.add_node;
dag.add_edge.unwrap;
dag.add_edge.unwrap;
// Compute attention scores
let attention = new;
let scores = attention.forward.unwrap;
Modules
dag- Core DAG data structures and algorithmsattention- 7 attention mechanisms + policy-driven selectionsona- Self-Optimizing Neural Architecture with adaptive learningmincut- Subpolynomial bottleneck detection (the central control signal)healing- Reactive + predictive self-healingqudag- QuDAG network integration with bounded sync frequency
Core Components
DAG (Directed Acyclic Graph)
The QueryDag structure represents query execution plans as directed acyclic graphs. Each node represents an operator (scan, filter, join, etc.) and edges represent data flow.
use ;
let mut dag = new;
let scan = dag.add_node;
let filter = dag.add_node;
dag.add_edge.unwrap;
Attention Mechanisms + Policy Layer
Seven attention mechanisms with dynamic policy-driven selection:
| Mechanism | When to Use | Trigger |
|---|---|---|
| Topological | Default baseline | Low variance |
| Causal Cone | Downstream impact analysis | Write-heavy patterns |
| Critical Path | Latency-bound queries | p99 > 2x p50 |
| MinCut Gated | Bottleneck-aware weighting | Cut tension rising |
| Hierarchical Lorentz | Deep hierarchical queries | Depth > 10 |
| Parallel Branch | Wide parallel execution | Branch count > 3 |
| Temporal BTSP | Time-series workloads | Temporal patterns |
use ;
use DagMinCutEngine;
// Policy-driven attention selection based on MinCut stress
let mut selector = new;
let mut mincut = new;
// Dynamic switching based on cut tension
let analysis = mincut.analyze_bottlenecks?;
let policy = if analysis.max_tension > 0.7 else if analysis.latency_variance > 2.0 else ;
let scores = selector.select_and_apply?;
SONA (Self-Optimizing Neural Architecture)
Adaptive learning with explicit data structures. SONA runs post-query in background, never blocking execution.
State Vector Structure:
/// SONA maintains per-DAG-pattern state vectors
use ;
let config = SonaConfig ;
let mut sona = new;
// Pre-query: Get enhanced embedding (fast path)
let enhanced = sona.pre_query;
// Execute query... (SONA doesn't block here)
let execution_time = execute_query;
// Post-query: Record trajectory (async, background)
sona.post_query;
// Background learning (runs in separate thread)
sona.background_learn; // Updates LoRA weights, EWC consolidation
MinCut Optimization (Central Control Signal)
The MinCut engine is the coherence boundary. Rising cut tension triggers attention switching, SONA re-weighting, and predictive healing.
use ;
let mut engine = new;
let analysis = engine.analyze_bottlenecks?;
// Tension signal drives the whole system
if analysis.max_tension > 0.7
for bottleneck in &analysis.bottlenecks
Self-Healing (Reactive + Predictive)
Self-healing responds to anomalies (reactive) and rising MinCut tension (predictive).
use ;
let mut orchestrator = new;
// Reactive: Z-score anomaly detection
orchestrator.add_detector;
// Predictive: Rising cut tension triggers early intervention
orchestrator.enable_predictive;
// Observe metrics
orchestrator.observe;
orchestrator.observe_mincut;
// Healing cycle: reactive + predictive
let result = orchestrator.run_cycle;
println!;
External Cost Model Trait
Plug in cost models for PostgreSQL, embedded, or chip-level schedulers without forking logic.
/// Trait for external cost estimation
/// PostgreSQL cost model (uses pg_catalog statistics)
/// Embedded systems cost model (memory-bound)
/// Chip-level cost model (cycle-accurate)
// Plug into DAG analysis
let mut dag = with_cost_model;
QuDAG Integration (Bounded Sync)
Quantum-resistant distributed learning with explicit sync frequency bounds.
use ;
let client = new;
// Sync only mature, validated patterns
client.sync_patterns.await?;
// Receive network-learned patterns (also bounded)
let network_patterns = client.receive_patterns.await?;
sona.merge_network_patterns;
End-to-End Example: Query Convergence
A slow query converges over several runs. One file, no prose, just logs.
$ cargo run --example convergence_demo
[run 1] query: SELECT * FROM vectors WHERE embedding <-> $1 < 0.5
dag: 4 nodes, 3 edges
attention: topological (default)
mincut_tension: 0.23
latency: 847ms (baseline: 850ms, improvement: 0.4%)
sona: recorded trajectory, pattern_id=0x7a3f
[run 2] same query, different params
attention: topological
mincut_tension: 0.31 (rising)
latency: 812ms (improvement: 4.5%)
sona: pattern match, applying lora_weights
[run 3]
attention: topological
mincut_tension: 0.58 (approaching threshold)
latency: 623ms (improvement: 26.7%)
sona: lora adaptation complete, ewc consolidating
[run 4]
mincut_tension: 0.71 > 0.7 (THRESHOLD)
--> switching attention: topological -> mincut_gated
--> healing: predictive intervention queued
attention: mincut_gated
latency: 412ms (improvement: 51.5%)
sona: boosting learning rate 2x for this pattern
[run 5]
attention: mincut_gated (sticky after tension spike)
mincut_tension: 0.45 (stabilizing)
latency: 398ms (improvement: 53.2%)
healing: predictive reindex completed in background
[run 10]
attention: mincut_gated
mincut_tension: 0.22 (stable)
latency: 156ms (improvement: 81.6%)
sona: pattern mature, queued for qudag sync
[qudag sync] pattern 0x7a3f synced to network
peers learning from our optimization
Examples
The examples/ directory contains:
basic_usage.rs- DAG creation and basic operationsattention_selection.rs- Policy-driven attention switchinglearning_workflow.rs- SONA learning with explicit state vectorsself_healing.rs- Reactive and predictive healingconvergence_demo.rs- End-to-end query convergence logs
WASM Target
Minimal WASM build for browser and embedded systems.
| Metric | Value |
|---|---|
| Raw size | 130 KB |
| Gzipped | 58 KB |
| API surface | 13 methods |
# Build WASM
# With wee_alloc for even smaller size
Performance Targets
| Component | Target | Notes |
|---|---|---|
| Attention (100 nodes) | <100μs | All 7 mechanisms |
| MicroLoRA adaptation | <100μs | Rank-2, per-operator |
| Pattern search (10K) | <2ms | K-means++ indexing |
| MinCut update | O(n^0.12) | Subpolynomial amortized |
| Anomaly detection | <50μs | Z-score, streaming |
| Predictive healing | <1ms | Tension-based lookahead |
| QuDAG sync | Bounded | 1min-1hr adaptive |
Architecture
┌─────────────────────────────────────────────────────────────┐
│ Query DAG Layer │
│ (Operators, Edges, Topological Sort) │
│ + External Cost Model Trait │
└───────────────────────────┬─────────────────────────────────┘
│
┌─────────────┴─────────────┐
│ │
┌──────────▼──────────┐ ┌─────────▼─────────┐
│ Attention Layer │ │ MinCut Engine │
│ (7 mechanisms) │◄────│ (Control Signal) │
│ + Policy Selector │ │ O(n^0.12) │
└──────────┬──────────┘ └─────────┬─────────┘
│ │
│ ┌─────────────────────┤
│ │ │
┌──────────▼────▼─────┐ ┌─────────▼─────────┐
│ SONA Engine │ │ Self-Healing │
│ (Post-Query Learn) │ │ (Reactive + Pred) │
│ MicroLoRA + EWC │ │ Tension-Driven │
└──────────┬──────────┘ └─────────┬─────────┘
│ │
└────────────┬────────────┘
│
┌────────────▼────────────┐
│ QuDAG Sync Layer │
│ (Bounded Frequency) │
│ ML-KEM + Differential │
└─────────────────────────┘
Development
# Run tests
# Run benchmarks
# Check documentation
Integration with RuVector
This crate is part of the RuVector ecosystem:
ruvector-core- Core vector operationsruvector-dag-wasm- Browser/embedded WASM target (58KB gzipped)ruvector-postgres- PostgreSQL extension with 50+ SQL functionsruvector-qudag- Full QuDAG consensus client
License
Apache-2.0 OR MIT