Squashed 'vendor/ruvector/' content from commit b64c2172

git-subtree-dir: vendor/ruvector
git-subtree-split: b64c21726f2bb37286d9ee36a7869fef60cc6900
This commit is contained in:
ruv
2026-02-28 14:39:40 -05:00
commit d803bfe2b1
7854 changed files with 3522914 additions and 0 deletions

95
.claude/hooks/bench-runner.sh Executable file
View File

@@ -0,0 +1,95 @@
#!/bin/bash
# Benchmark runner with baseline comparison for RuVector
# Integrates with criterion benchmarks and stores results
set -e
CRATE="${1:-all}"
BASELINE_DIR="/workspaces/ruvector/.claude-flow/metrics/benchmarks"
mkdir -p "$BASELINE_DIR"
cd /workspaces/ruvector
echo "📊 RuVector Benchmark Runner"
echo "============================"
echo ""
run_bench() {
local crate=$1
local bench_name=$2
local output_file="$BASELINE_DIR/${crate}-$(date +%Y%m%d-%H%M%S).json"
echo "🏃 Running: cargo bench -p $crate"
# Run benchmark and capture output
if cargo bench -p "$crate" -- --noplot 2>&1 | tee /tmp/bench-output.txt; then
# Extract timing info from criterion output
grep -E "time:" /tmp/bench-output.txt | head -10
# Store raw output
cp /tmp/bench-output.txt "$output_file.txt"
echo ""
echo "📁 Results saved to: $output_file.txt"
else
echo "⚠️ Benchmark failed for $crate"
fi
}
case "$CRATE" in
"all")
echo "Running all available benchmarks..."
echo ""
# Core benchmarks
if [ -d "crates/ruvector-bench" ]; then
run_bench "ruvector-bench" "core"
fi
# MinCut benchmarks
if [ -d "crates/ruvector-mincut" ]; then
run_bench "ruvector-mincut" "mincut"
fi
# Attention benchmarks
if [ -d "crates/ruvector-attention" ]; then
run_bench "ruvector-attention" "attention"
fi
;;
"core"|"ruvector-bench")
run_bench "ruvector-bench" "core"
;;
"mincut"|"ruvector-mincut")
run_bench "ruvector-mincut" "mincut"
;;
"attention"|"ruvector-attention")
run_bench "ruvector-attention" "attention"
;;
"graph"|"ruvector-graph")
run_bench "ruvector-graph" "graph"
;;
"quick")
echo "Running quick sanity benchmarks..."
cargo bench -p ruvector-bench -- --noplot "insert" 2>&1 | tail -10
;;
*)
echo "Usage: $0 [all|core|mincut|attention|graph|quick|<crate-name>]"
echo ""
echo "Available benchmark crates:"
echo " core/ruvector-bench - Core vector operations"
echo " mincut - Min-cut algorithms"
echo " attention - Attention mechanisms"
echo " graph - Graph operations"
echo " quick - Fast sanity check"
exit 1
;;
esac
echo ""
echo "✅ Benchmarks complete"
echo "📁 Results in: $BASELINE_DIR/"

104
.claude/hooks/crate-context.sh Executable file
View File

@@ -0,0 +1,104 @@
#!/bin/bash
# Load crate-specific context for intelligent code assistance
# Outputs relevant examples, tests, and documentation paths
set -e
FILE="$1"
if [ -z "$FILE" ]; then
echo "Usage: $0 <file_path>"
exit 1
fi
cd /workspaces/ruvector
# Detect crate from file path
CRATE_DIR=$(echo "$FILE" | grep -oP "crates/[^/]+" | head -1 || echo "")
CRATE_NAME=""
if [ -n "$CRATE_DIR" ]; then
CRATE_NAME=$(basename "$CRATE_DIR")
fi
echo "{"
echo " \"file\": \"$FILE\","
echo " \"crate\": \"$CRATE_NAME\","
# Find related test files
echo " \"tests\": ["
TESTS=$(find "$CRATE_DIR/tests" -name "*.rs" 2>/dev/null | head -5 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
echo "$TESTS"
echo " ],"
# Find related examples
echo " \"examples\": ["
EXAMPLES=$(find "$CRATE_DIR/examples" -name "*.rs" 2>/dev/null | head -5 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
if [ -z "$EXAMPLES" ]; then
# Check examples/ directory at root
case "$CRATE_NAME" in
"ruvector-core"|"ruvector-wasm")
EXAMPLES=$(find "examples/wasm" "examples/wasm-react" -name "*.ts" -o -name "*.tsx" 2>/dev/null | head -3 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
;;
"ruvector-graph"*)
EXAMPLES=$(find "examples" -path "*graph*" -name "*.rs" 2>/dev/null | head -3 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
;;
"ruvector-mincut"*)
EXAMPLES=$(find "examples/mincut" -name "*.rs" 2>/dev/null | head -3 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
;;
esac
fi
echo "$EXAMPLES"
echo " ],"
# Find related documentation
echo " \"docs\": ["
DOCS=$(find "$CRATE_DIR" -name "*.md" 2>/dev/null | head -5 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
if [ -z "$DOCS" ]; then
case "$CRATE_NAME" in
"ruvector-postgres"*)
DOCS=$(find "docs/postgres" -name "*.md" 2>/dev/null | head -5 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
;;
"rvlite")
DOCS=$(find "crates/rvlite/docs" -name "*.md" 2>/dev/null | head -5 | while read f; do echo " \"$f\","; done | sed '$ s/,$//')
;;
esac
fi
echo "$DOCS"
echo " ],"
# Key dependencies
echo " \"key_deps\": ["
if [ -f "$CRATE_DIR/Cargo.toml" ]; then
grep -E "^\[dependencies\]" -A 20 "$CRATE_DIR/Cargo.toml" 2>/dev/null | grep -E "^[a-z]" | head -5 | while read line; do
DEP=$(echo "$line" | cut -d'=' -f1 | tr -d ' ')
echo " \"$DEP\","
done | sed '$ s/,$//'
fi
echo " ],"
# Suggest related commands
echo " \"commands\": {"
case "$CRATE_NAME" in
"ruvector-core"|"ruvector-bench")
echo " \"test\": \"cargo test -p $CRATE_NAME\","
echo " \"bench\": \"cargo bench -p ruvector-bench\","
echo " \"check\": \"cargo check -p $CRATE_NAME\""
;;
"rvlite"|"ruvector-wasm"|"ruvector-graph-wasm"|"ruvector-gnn-wasm")
echo " \"build\": \"wasm-pack build --target web --release\","
echo " \"test\": \"wasm-pack test --headless --chrome\","
echo " \"size\": \".claude/hooks/wasm-size-check.sh $CRATE_NAME\""
;;
"ruvector-postgres")
echo " \"build\": \"cargo pgrx package\","
echo " \"test\": \"cargo pgrx test\","
echo " \"run\": \"cargo pgrx run\""
;;
*)
echo " \"test\": \"cargo test -p $CRATE_NAME\","
echo " \"check\": \"cargo check -p $CRATE_NAME\""
;;
esac
echo " }"
echo "}"

97
.claude/hooks/post-rust-edit.sh Executable file
View File

@@ -0,0 +1,97 @@
#!/bin/bash
# Post-edit hook for Rust files in RuVector
# Runs format check, clippy, and optional benchmarks
set -e
FILE="$1"
RUN_BENCH="${2:-false}"
if [ -z "$FILE" ]; then
echo "Usage: $0 <file_path> [run_bench]"
exit 1
fi
EXT="${FILE##*.}"
if [ "$EXT" != "rs" ]; then
exit 0 # Not a Rust file
fi
cd /workspaces/ruvector
# Detect crate
CRATE_DIR=$(echo "$FILE" | grep -oP "crates/[^/]+" | head -1 || echo "")
CRATE_NAME=""
if [ -n "$CRATE_DIR" ]; then
CRATE_NAME=$(basename "$CRATE_DIR")
fi
echo "🦀 Post-edit checks for: $FILE"
# 1. Format check (don't auto-fix, just report)
echo ""
echo "📐 Checking format..."
if cargo fmt --check -- "$FILE" 2>/dev/null; then
echo " ✅ Format OK"
else
echo " ⚠️ Format issues detected (run: cargo fmt)"
fi
# 2. Quick clippy check for the crate
if [ -n "$CRATE_NAME" ]; then
echo ""
echo "📎 Running clippy for $CRATE_NAME..."
CLIPPY_OUT=$(cargo clippy -p "$CRATE_NAME" --message-format=short 2>&1 | grep -E "^(warning|error)" | head -5)
if [ -z "$CLIPPY_OUT" ]; then
echo " ✅ No clippy warnings"
else
echo "$CLIPPY_OUT"
fi
fi
# 3. Check for test file and suggest tests
TEST_FILE="${FILE%.rs}_test.rs"
if [ -f "$TEST_FILE" ]; then
echo ""
echo "🧪 Test file exists: $TEST_FILE"
fi
# 4. WASM size check for wasm crates
if echo "$FILE" | grep -qE "wasm|rvlite"; then
echo ""
echo "📏 WASM crate modified - consider running:"
echo " cd crates/rvlite && wasm-pack build --release"
echo " ls -lh pkg/*.wasm"
fi
# 5. Optional benchmark for performance-critical crates
if [ "$RUN_BENCH" = "true" ]; then
case "$CRATE_NAME" in
"ruvector-core"|"ruvector-bench")
echo ""
echo "📊 Running benchmarks..."
cargo bench -p ruvector-bench -- --noplot 2>&1 | tail -20
;;
"ruvector-mincut")
echo ""
echo "📊 Running mincut benchmarks..."
cargo bench -p ruvector-mincut -- --noplot 2>&1 | tail -20
;;
"ruvector-attention")
echo ""
echo "📊 Running attention benchmarks..."
cargo bench -p ruvector-attention -- --noplot 2>&1 | tail -20
;;
esac
fi
# Store metrics
METRICS_DIR="/workspaces/ruvector/.claude-flow/metrics"
mkdir -p "$METRICS_DIR"
# Record edit in metrics
echo "{\"file\": \"$FILE\", \"crate\": \"$CRATE_NAME\", \"timestamp\": \"$(date -Iseconds)\"}" >> "$METRICS_DIR/edit-log.jsonl"
echo ""
echo "✅ Post-edit checks complete"

97
.claude/hooks/rust-check.sh Executable file
View File

@@ -0,0 +1,97 @@
#!/bin/bash
# Rust-specific pre-edit hook for RuVector
# Runs cargo check, clippy hints, and detects crate context
set -e
FILE="$1"
if [ -z "$FILE" ]; then
echo "Usage: $0 <file_path>"
exit 1
fi
EXT="${FILE##*.}"
if [ "$EXT" != "rs" ]; then
exit 0 # Not a Rust file
fi
cd /workspaces/ruvector
# Detect which crate this file belongs to
CRATE_DIR=$(echo "$FILE" | grep -oP "crates/[^/]+" | head -1 || echo "")
CRATE_NAME=""
if [ -n "$CRATE_DIR" ]; then
CRATE_NAME=$(basename "$CRATE_DIR")
echo "🦀 Crate: $CRATE_NAME"
# Show crate-specific context
case "$CRATE_NAME" in
"ruvector-core")
echo " 📊 Core vector engine (HNSW, SIMD, quantization)"
echo " 📦 Key: VectorStore, HnswIndex, Distance metrics"
;;
"rvlite")
echo " 🌐 WASM standalone DB (SQL/SPARQL/Cypher)"
echo " 📦 Key: RvLite, SqlExecutor, CypherParser"
echo " ⚠️ Size target: <3MB gzipped"
;;
"ruvector-wasm")
echo " 🌐 WASM bindings for ruvector-core"
echo " 📦 Key: WasmVectorStore, IndexedDB storage"
;;
"ruvector-graph"|"ruvector-graph-wasm"|"ruvector-graph-node")
echo " 🕸️ Graph database with Cypher support"
echo " 📦 Key: GraphStore, CypherQuery, HyperEdge"
;;
"ruvector-gnn"|"ruvector-gnn-wasm"|"ruvector-gnn-node")
echo " 🧠 Graph Neural Networks (GCN, GraphSAGE, GAT)"
echo " 📦 Key: GnnLayer, MessagePassing, Aggregation"
;;
"ruvector-postgres")
echo " 🐘 PostgreSQL extension (pgvector compatible)"
echo " 📦 Key: pgrx, SQL functions, background workers"
;;
"sona")
echo " 🎓 ReasoningBank with 9 RL algorithms"
echo " 📦 Key: Trajectory, Verdict, LoRA, EWC++"
;;
"ruvector-mincut"|"ruvector-mincut-wasm"|"ruvector-mincut-node")
echo " ✂️ Subpolynomial dynamic min-cut algorithm"
echo " 📦 Key: ContractedGraph, LambdaCut, SparseCertificate"
;;
"ruvector-attention"|"ruvector-attention-wasm"|"ruvector-attention-node")
echo " 👁️ 39+ attention mechanisms"
echo " 📦 Key: MultiHeadAttention, GeometricAttention"
;;
"ruvector-tiny-dancer"|"ruvector-tiny-dancer-wasm"|"ruvector-tiny-dancer-node")
echo " 💃 FastGRNN neural router for agents"
echo " 📦 Key: Router, FastGRNN, CircuitBreaker"
;;
"ruvector-cli")
echo " ⌨️ CLI and MCP server"
echo " 📦 Key: Commands, MCP protocol, REST API"
;;
*)
echo " 📦 Crate: $CRATE_NAME"
;;
esac
# Quick cargo check for the specific crate
echo ""
echo "🔍 Running cargo check -p $CRATE_NAME..."
if cargo check -p "$CRATE_NAME" --message-format=short 2>&1 | head -10; then
echo "✅ Cargo check passed"
else
echo "⚠️ Check for warnings/errors above"
fi
fi
# Check for WASM-related files
if echo "$FILE" | grep -qE "wasm|rvlite"; then
echo ""
echo "📏 WASM file detected - size considerations apply"
echo " Target: <3MB gzipped for rvlite"
fi
echo ""

103
.claude/hooks/wasm-size-check.sh Executable file
View File

@@ -0,0 +1,103 @@
#!/bin/bash
# WASM size checker for rvlite and other WASM crates
# Ensures bundles stay within target size (<3MB gzipped)
set -e
CRATE="${1:-rvlite}"
MAX_SIZE_KB="${2:-3072}" # 3MB default
cd /workspaces/ruvector
echo "📏 WASM Size Checker"
echo "==================="
echo ""
check_wasm_size() {
local crate_dir=$1
local pkg_dir="$crate_dir/pkg"
if [ ! -d "$pkg_dir" ]; then
echo "⚠️ No pkg/ directory found for $crate_dir"
echo " Run: cd $crate_dir && wasm-pack build --release"
return 1
fi
echo "📦 Checking: $crate_dir"
# Find .wasm files
for wasm_file in "$pkg_dir"/*.wasm; do
if [ -f "$wasm_file" ]; then
# Raw size
RAW_SIZE=$(stat -c%s "$wasm_file" 2>/dev/null || stat -f%z "$wasm_file")
RAW_SIZE_KB=$((RAW_SIZE / 1024))
# Gzipped size
GZIP_SIZE=$(gzip -c "$wasm_file" | wc -c)
GZIP_SIZE_KB=$((GZIP_SIZE / 1024))
echo " 📄 $(basename "$wasm_file")"
echo " Raw: ${RAW_SIZE_KB} KB"
echo " Gzipped: ${GZIP_SIZE_KB} KB"
if [ "$GZIP_SIZE_KB" -gt "$MAX_SIZE_KB" ]; then
echo " ❌ EXCEEDS target of ${MAX_SIZE_KB} KB!"
return 1
else
PERCENT=$((GZIP_SIZE_KB * 100 / MAX_SIZE_KB))
echo "${PERCENT}% of budget"
fi
fi
done
return 0
}
case "$CRATE" in
"all")
echo "Checking all WASM crates..."
echo ""
for dir in crates/*-wasm crates/rvlite; do
if [ -d "$dir" ]; then
check_wasm_size "$dir" || true
echo ""
fi
done
;;
"rvlite")
check_wasm_size "crates/rvlite"
;;
"ruvector-wasm"|"core")
check_wasm_size "crates/ruvector-wasm"
;;
"graph"|"ruvector-graph-wasm")
check_wasm_size "crates/ruvector-graph-wasm"
;;
"gnn"|"ruvector-gnn-wasm")
check_wasm_size "crates/ruvector-gnn-wasm"
;;
"attention"|"ruvector-attention-wasm")
check_wasm_size "crates/ruvector-attention-wasm"
;;
"mincut"|"ruvector-mincut-wasm")
check_wasm_size "crates/ruvector-mincut-wasm"
;;
*)
if [ -d "crates/$CRATE" ]; then
check_wasm_size "crates/$CRATE"
else
echo "Usage: $0 [all|rvlite|core|graph|gnn|attention|mincut|<crate-name>]"
exit 1
fi
;;
esac
echo ""
echo "✅ Size check complete"