ruvector-verified
Proof-carrying vector operations for Rust. Every dimension check, HNSW insert, and pipeline composition produces a machine-checked proof witness -- catching bugs that assert! misses, with less than 2% runtime overhead.
Built on lean-agentic dependent types. Part of the RuVector ecosystem.
The Problem
Vector databases silently corrupt results when dimensions mismatch. A 384-dim query against a 768-dim index doesn't panic -- it returns wrong answers. Traditional approaches either:
- Runtime
assert!-- panics in production, no proof trail - Const generics -- catches errors at compile time, but can't handle dynamic dimensions from user input, config files, or model outputs
The Solution
ruvector-verified generates formal proofs that dimensions match, types align, and pipelines compose correctly. Each proof is a replayable term -- not just a boolean check -- producing an 82-byte attestation that can be stored, audited, or embedded in RVF witness chains.
use ;
let mut env = new; // ~470ns, pre-loaded with 11 type declarations
// Prove dimensions match -- returns a reusable proof term, not just Ok/Err
let proof_id = prove_dim_eq?; // ~500ns first call, ~15ns cached
// Wrong dimensions produce typed errors, not panics
let err = prove_dim_eq; // Err(DimensionMismatch { expected: 384, actual: 128 })
// Batch-verify 1000 vectors in ~11us (11ns per vector)
let vecs: = vectors.iter.map.collect;
let verified = verify_batch_dimensions?;
assert_eq!; // verified.proof_id traces back to the proof term
// Create an 82-byte attestation for audit/storage
let attestation = create_attestation;
let bytes = attestation.to_bytes; // embeddable in RVF witness chain (type 0x0E)
Key Capabilities
- Sub-microsecond proofs -- dimension equality in 496ns, batch verification at 11ns/vector
- Proof-carrying results -- every
VerifiedOp<T>bundles the result with its proof term ID - 3-tier gated routing -- automatically routes proofs to Reflex (<10ns), Standard (<1us), or Deep (<100us) based on complexity
- 82-byte attestations -- formal proof witnesses that serialize into RVF containers
- Thread-local pools -- zero-contention resource reuse, 876ns acquire with auto-return
- Pipeline composition -- type-safe
A -> B >> B -> Cstage chaining with machine-checked proofs - Works with
Vec<f32>-- no special array types required, verifies standard Rust slices
Performance
All operations benchmarked on a single core (no SIMD, no parallelism):
| Operation | Latency | Notes |
|---|---|---|
ProofEnvironment::new() |
466ns | Pre-loads 11 type declarations |
prove_dim_eq(384, 384) |
496ns | FxHash-cached, subsequent calls ~15ns |
mk_vector_type(384) |
503ns | Cached after first call |
verify_batch_dimensions(1000 vecs) |
~11us | Amortized ~11ns/vector |
FastTermArena::intern() (hit) |
1.6ns | 4-wide linear probe, 99%+ hit rate |
gated::route_proof() |
1.2ns | 3-tier routing decision |
ConversionCache::get() |
9.6ns | Open-addressing, 1000 entries |
pools::acquire() |
876ns | Thread-local, auto-return on Drop |
ProofAttestation::roundtrip |
<1ns | 82-byte serialize/deserialize |
env.reset() |
379ns | O(1) pointer reset |
Overhead vs unverified operations: <2% on batch vector ingest.
Features
| Feature | Default | Description |
|---|---|---|
fast-arena |
- | FastTermArena: O(1) bump allocation with 4-wide dedup cache |
simd-hash |
- | AVX2/NEON accelerated hash-consing |
gated-proofs |
- | 3-tier Reflex/Standard/Deep proof routing |
ultra |
- | All optimizations (fast-arena + simd-hash + gated-proofs) |
hnsw-proofs |
- | Verified HNSW insert/query (requires ruvector-core) |
rvf-proofs |
- | RVF witness chain integration |
coherence-proofs |
- | Sheaf coherence verification |
all-proofs |
- | All proof integrations |
serde |
- | Serialization for ProofAttestation |
# Minimal: just dimension proofs
= "0.1.0"
# All optimizations (recommended for production)
= { = "0.1.0", = ["ultra"] }
# Everything
= { = "0.1.0", = ["ultra", "all-proofs", "serde"] }
Architecture
+-----------------------+
| ProofEnvironment | Pre-loaded type declarations
| (symbols, cache, | Nat, RuVec, Eq, HnswIndex, ...
| term allocator) |
+-----------+-----------+
|
+------------------------+------------------------+
| | |
+-------v-------+ +----------v----------+ +--------v--------+
| vector_types | | pipeline | | proof_store |
| prove_dim_eq | | compose_stages | | ProofAttestation|
| verify_batch | | compose_chain | | 82-byte witness |
+-------+-------+ +----------+----------+ +--------+--------+
| | |
+----------- gated routing (3-tier) -------------+
| Reflex | Standard | Deep |
+-------- FastTermArena (bump + dedup) ----------+
| ConversionCache (open-addressing) |
+---------- pools (thread-local reuse) ----------+
Comparison
| Feature | ruvector-verified | Runtime assert! |
ndarray shape check |
nalgebra const generics |
|---|---|---|---|---|
| Proof-carrying operations | Yes | No | No | No |
| Dimension errors caught | At proof time | At runtime (panic) | At runtime | At compile time |
| Supports dynamic dimensions | Yes | Yes | Yes | No |
| Formal attestation (82-byte witness) | Yes | No | No | No |
| Pipeline type composition | Yes | No | No | Partial |
| Sub-microsecond overhead | Yes | Yes | Yes | Zero |
Works with existing Vec<f32> |
Yes | Yes | No | No |
| 3-tier proof routing | Yes | N/A | N/A | N/A |
| Thread-local resource pooling | Yes | N/A | N/A | N/A |
Core API
Dimension Proofs
use ;
let mut env = new;
// Prove dimensions match (returns proof term ID)
let proof_id = prove_dim_eq?;
// Verify a single vector against an index
let vector = vec!;
let verified = verified_dim_check?;
// verified.proof_id is the machine-checked proof
// Batch verify
let batch: = vectors.iter.map.collect;
let batch_ok = verify_batch_dimensions?;
assert_eq!;
Pipeline Composition
use ;
let mut env = new;
// Type-safe pipeline: Embedding(384) -> Quantized(128) -> Index
let embed: = new;
let quant: = new;
let composed = compose_stages?;
assert_eq!;
Proof Attestation (82-byte Witness)
use ;
let mut env = new;
let proof_id = env.alloc_term;
let attestation = create_attestation;
let bytes = attestation.to_bytes; // exactly 82 bytes
assert_eq!;
// Round-trip
let recovered = from_bytes?;
FastTermArena (feature: fast-arena)
O(1) bump allocation with 4-wide linear probe dedup cache. Modeled after ruvector-solver's SolverArena.
use ;
let arena = with_capacity;
// First intern: cache miss, allocates new term
let = arena.intern;
assert!;
// Second intern: cache hit, returns same ID in ~1.6ns
let = arena.intern;
assert!;
assert_eq!;
// O(1) reset
arena.reset;
assert_eq!;
// Statistics
let stats = arena.stats;
println!;
Gated Proof Routing (feature: gated-proofs)
Routes proof obligations to the cheapest sufficient compute tier. Inspired by ruvector-mincut-gated-transformer's GateController.
use ;
let env = new;
// Reflexivity -> Reflex tier (~1.2ns)
let decision = route_proof;
assert!;
// Dimension equality -> Reflex tier (literal comparison)
let decision = route_proof;
assert_eq!;
// Long pipeline -> Deep tier (full kernel)
let decision = route_proof;
assert!;
Tier latency targets:
| Tier | Latency | Use Case |
|---|---|---|
| Reflex | <10ns | a = a, literal dimension match |
| Standard | <1us | Shallow type application, short pipelines |
| Deep | <100us | Full kernel with 10,000 step budget |
ConversionCache
Open-addressing conversion result cache with FxHash. Modeled after ruvector-mincut's PathDistanceCache.
use ConversionCache;
let mut cache = with_capacity;
cache.insert;
assert_eq!;
let stats = cache.stats;
println!;
Thread-Local Pools
Zero-contention resource reuse via Drop-based auto-return.
use pools;
// auto-returned to pool on drop
let = pool_stats;
Verified HNSW operations that prove dimensionality and metric compatibility before allowing insert/query.
use ;
let mut env = new;
// Prove insert preconditions
let vector = vec!;
let verified = verified_insert?;
assert_eq!;
assert_eq!;
// Build typed index type term
let index_type = mk_hnsw_index_type?;
All errors are typed via VerificationError:
use VerificationError;
match result
Error variants: DimensionMismatch, TypeCheckFailed, ProofConstructionFailed, ConversionTimeout, UnificationFailed, ArenaExhausted, DeclarationNotFound, AttestationError
ProofEnvironment::new() pre-registers these domain types:
| Symbol | Arity | Description |
|---|---|---|
Nat |
0 | Natural numbers (dimensions) |
RuVec |
1 | RuVec : Nat -> Type (dimension-indexed vector) |
Eq |
2 | Propositional equality |
Eq.refl |
1 | Reflexivity proof constructor |
DistanceMetric |
0 | L2, Cosine, Dot |
HnswIndex |
2 | HnswIndex : Nat -> DistanceMetric -> Type |
InsertResult |
0 | HNSW insert result |
PipelineStage |
2 | PipelineStage : Type -> Type -> Type |
# All benchmarks
# Quick run
# Specific group
Sample output (AMD EPYC, single core):
prove_dim_eq/384 time: [496 ns]
mk_vector_type/384 time: [503 ns]
ProofEnvironment::new time: [466 ns]
pool_acquire_release time: [876 ns]
env_reset time: [379 ns]
cache_lookup_1000_hits time: [9.6 us]
attestation_roundtrip time: [<1 ns]
See examples/rvf-kernel-optimized for a complete example that combines:
- Verified vector ingest with dimension proofs
- Linux kernel + eBPF embedding into RVF containers
- 3-tier gated proof routing
- FastTermArena dedup with 99%+ cache hit rate
- 82-byte proof attestations in the RVF witness chain
Minimum Supported Rust Version
1.77
License
MIT OR Apache-2.0