Ruvector GNN
A Graph Neural Network layer that makes HNSW vector search get smarter over time.
Most vector indexes return the same results every time you search. ruvector-gnn adds a GNN layer on top of HNSW that learns from your query patterns -- so search results actually improve with use. It runs message passing directly on the HNSW graph structure with SIMD acceleration, keeping latency low even on large indexes. Part of the RuVector ecosystem.
| ruvector-gnn | Standard HNSW Search | |
|---|---|---|
| Search quality | GNN re-ranks neighbors using learned attention weights -- results improve over time | Static ranking -- same results every time |
| Graph awareness | Operates directly on HNSW topology; understands graph structure | Treats index as a flat lookup table |
| Attention mechanisms | Multi-head GAT weighs which neighbors matter for each query | No attention -- all neighbors weighted equally |
| Inductive learning | GraphSAGE generalizes to unseen nodes without retraining | Cannot learn from new data |
| Hardware acceleration | SIMD-optimized aggregation; memory-mapped weights for large models | Basic distance calculations only |
| Deployment | Native Rust, Node.js (NAPI-RS), and WASM from the same crate | Typically single-platform |
Installation
Add ruvector-gnn to your Cargo.toml:
[]
= "0.1.1"
Feature Flags
[]
# Default with SIMD and memory mapping
= { = "0.1.1", = ["simd", "mmap"] }
# WASM-compatible build
= { = "0.1.1", = false, = ["wasm"] }
# Node.js bindings
= { = "0.1.1", = ["napi"] }
Available features:
simd(default): SIMD-optimized operationsmmap(default): Memory-mapped weight storagewasm: WebAssembly-compatible buildnapi: Node.js bindings via NAPI-RS
Key Features
| Feature | What It Does | Why It Matters |
|---|---|---|
| GCN Layers | Graph Convolutional Network forward pass over HNSW neighbors | Learns structural patterns in your data without manual feature engineering |
| GAT Layers | Multi-head Graph Attention with interpretable weights | Automatically discovers which neighbors are most relevant per query |
| GraphSAGE | Inductive learning with neighbor sampling | Handles new, unseen nodes without retraining the full model |
| SIMD Aggregation | Hardware-accelerated message passing | Keeps GNN overhead under 15 ms for 100K-node graphs |
| Memory Mapping | Large model weights loaded via mmap | Run models bigger than RAM; only pages what's needed |
| INT8/FP16 Quantization | Compressed weight storage | 2-4x smaller models with minimal accuracy loss |
| Custom Aggregators | Mean, max, and LSTM aggregation modes | Tune the aggregation strategy to your data distribution |
| Skip Connections | Residual connections for deep GNN stacks | Train deeper networks without vanishing gradients |
| Batch Processing | Parallel message passing with Rayon | Saturates all cores during training and inference |
| Layer Normalization | Normalize activations between layers | Stable training dynamics across different graph sizes |
Quick Start
Basic GCN Layer
use ;
use Array2;
Graph Attention Network
use ;
// Configure multi-head attention
let config = AttentionConfig ;
let gat = new?;
// Forward with attention
let = gat.forward_with_attention?;
// Attention weights for interpretability
for in attention_weights.iter.enumerate
GraphSAGE with Custom Aggregator
use ;
let config = SAGEConfig ;
let sage = new?;
// Mini-batch training with neighbor sampling
let embeddings = sage.forward_minibatch?;
Integration with Ruvector Core
use VectorDB;
use ;
// Load vector database
let db = open?;
// Create GNN that operates on HNSW structure
let gnn = new?;
// Get HNSW neighbors for message passing
let hnsw_graph = db.get_hnsw_graph?;
// Compute GNN embeddings
let gnn_embeddings = gnn.encode?;
// Enhanced search using GNN embeddings
let results = db.search_with_gnn?;
API Overview
Core Types
// GNN layer configuration
// Message passing interface
// Layer types
Layer Operations
Performance
Benchmarks (100K Nodes, Avg Degree 16)
Operation Latency (p50) GFLOPS
-----------------------------------------------------
GCN forward (1 layer) ~15ms 12.5
GAT forward (8 heads) ~45ms 8.2
GraphSAGE (2 layers) ~25ms 10.1
Message aggregation ~5ms 25.0
Memory Usage
Model Size Peak Memory
---------------------------------------
128 -> 64 (1 layer) ~50MB
128 -> 64 (4 layers) ~150MB
With mmap weights ~10MB (+ disk)
Related Crates
- ruvector-core - Core vector database engine
- ruvector-gnn-node - Node.js bindings
- ruvector-gnn-wasm - WebAssembly bindings
- ruvector-graph - Graph database engine
Documentation
- Main README - Complete project overview
- API Documentation - Full API reference
- GitHub Repository - Source code
License
MIT License - see LICENSE for details.