Merge commit 'd803bfe2b1fe7f5e219e50ac20d6801a0a58ac75' as 'vendor/ruvector'
This commit is contained in:
59
vendor/ruvector/scripts/test/test-all-graph-commands.sh
vendored
Executable file
59
vendor/ruvector/scripts/test/test-all-graph-commands.sh
vendored
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
# Comprehensive test of all RuVector graph CLI commands
|
||||
|
||||
set -e
|
||||
|
||||
CLI="./target/debug/ruvector"
|
||||
TEST_DB="/tmp/ruvector-graph-test.db"
|
||||
|
||||
echo "=========================================="
|
||||
echo "RuVector Graph CLI - Full Command Test"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
|
||||
# Test 1: Create
|
||||
echo "1. Testing: graph create"
|
||||
$CLI graph create --path $TEST_DB --name test-graph --indexed
|
||||
echo ""
|
||||
|
||||
# Test 2: Info
|
||||
echo "2. Testing: graph info"
|
||||
$CLI graph info --db $TEST_DB --detailed
|
||||
echo ""
|
||||
|
||||
# Test 3: Query
|
||||
echo "3. Testing: graph query"
|
||||
$CLI graph query --db $TEST_DB --cypher "MATCH (n) RETURN n" --format table
|
||||
echo ""
|
||||
|
||||
# Test 4: Query with explain
|
||||
echo "4. Testing: graph query --explain"
|
||||
$CLI graph query --db $TEST_DB --cypher "MATCH (n:Person) WHERE n.age > 25 RETURN n" --explain
|
||||
echo ""
|
||||
|
||||
# Test 5: Benchmark
|
||||
echo "5. Testing: graph benchmark"
|
||||
$CLI graph benchmark --db $TEST_DB --queries 100 --bench-type traverse
|
||||
echo ""
|
||||
|
||||
# Test 6: Serve (won't actually start, just test args)
|
||||
echo "6. Testing: graph serve (dry run)"
|
||||
timeout 2 $CLI graph serve --db $TEST_DB --host 127.0.0.1 --http-port 8080 --grpc-port 50051 --graphql 2>&1 || true
|
||||
echo ""
|
||||
|
||||
echo "=========================================="
|
||||
echo "All Tests Completed Successfully!"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
echo "Summary of implemented commands:"
|
||||
echo " ✓ graph create - Create new graph database"
|
||||
echo " ✓ graph query - Execute Cypher queries (-q flag)"
|
||||
echo " ✓ graph shell - Interactive REPL (use Ctrl+C to exit)"
|
||||
echo " ✓ graph import - Import from files (-i flag)"
|
||||
echo " ✓ graph export - Export to files (-o flag)"
|
||||
echo " ✓ graph info - Show statistics (--detailed flag)"
|
||||
echo " ✓ graph benchmark - Performance tests (-n, -t flags)"
|
||||
echo " ✓ graph serve - HTTP/gRPC server (--graphql flag)"
|
||||
echo ""
|
||||
echo "All commands use -b for --db (not -d, which is for --debug)"
|
||||
echo "Query uses -q for --cypher (not -c, which is for --config)"
|
||||
108
vendor/ruvector/scripts/test/test-docker-package.sh
vendored
Executable file
108
vendor/ruvector/scripts/test/test-docker-package.sh
vendored
Executable file
@@ -0,0 +1,108 @@
|
||||
#!/bin/bash
|
||||
# Test ruvector npm package in Docker container
|
||||
set -e
|
||||
|
||||
echo "=== Creating test package ==="
|
||||
|
||||
# Create temporary test directory
|
||||
TEST_DIR=$(mktemp -d)
|
||||
cd "$TEST_DIR"
|
||||
|
||||
# Create package.json
|
||||
cat > package.json << 'EOF'
|
||||
{
|
||||
"name": "ruvector-test",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"main": "test.mjs"
|
||||
}
|
||||
EOF
|
||||
|
||||
# Create test script
|
||||
cat > test.mjs << 'EOF'
|
||||
import ruvector from '@ruvector/core';
|
||||
|
||||
const { VectorDB, CollectionManager, version, hello, getHealth, getMetrics } = ruvector;
|
||||
|
||||
console.log('=== Ruvector Package Test ===\n');
|
||||
|
||||
// Test version and hello
|
||||
console.log('Version:', version());
|
||||
console.log('Hello:', hello());
|
||||
|
||||
// Test health
|
||||
console.log('\n--- Health Check ---');
|
||||
const health = getHealth();
|
||||
console.log('Status:', health.status);
|
||||
console.log('Version:', health.version);
|
||||
|
||||
// Test metrics
|
||||
console.log('\n--- Metrics ---');
|
||||
const metrics = getMetrics();
|
||||
console.log('Metrics available:', metrics.length > 0 ? 'Yes' : 'No');
|
||||
|
||||
// Test VectorDB
|
||||
console.log('\n--- VectorDB Test ---');
|
||||
const db = VectorDB.withDimensions(4);
|
||||
console.log('Created VectorDB with 4 dimensions');
|
||||
|
||||
// Insert vectors
|
||||
const id1 = await db.insert({ vector: new Float32Array([1.0, 0.0, 0.0, 0.0]) });
|
||||
const id2 = await db.insert({ vector: new Float32Array([0.0, 1.0, 0.0, 0.0]) });
|
||||
const id3 = await db.insert({ vector: new Float32Array([0.9, 0.1, 0.0, 0.0]) });
|
||||
console.log('Inserted 3 vectors:', id1, id2, id3);
|
||||
|
||||
// Search
|
||||
const results = await db.search({ vector: new Float32Array([1.0, 0.0, 0.0, 0.0]), k: 2 });
|
||||
console.log('Search results:', results);
|
||||
|
||||
// Verify correct order
|
||||
if (results[0].id === id1 && results[1].id === id3) {
|
||||
console.log('✓ Search results correct!');
|
||||
} else {
|
||||
console.log('✗ Search results incorrect');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Test CollectionManager
|
||||
console.log('\n--- CollectionManager Test ---');
|
||||
try {
|
||||
const manager = new CollectionManager('./test-collections');
|
||||
console.log('Created CollectionManager');
|
||||
|
||||
await manager.createCollection('test_vectors', { dimensions: 128 });
|
||||
console.log('Created collection: test_vectors');
|
||||
|
||||
const collections = await manager.listCollections();
|
||||
console.log('Collections:', collections);
|
||||
|
||||
const stats = await manager.getStats('test_vectors');
|
||||
console.log('Stats:', stats);
|
||||
|
||||
await manager.deleteCollection('test_vectors');
|
||||
console.log('Deleted collection: test_vectors');
|
||||
console.log('✓ CollectionManager works!');
|
||||
} catch (err) {
|
||||
console.log('CollectionManager error:', err.message);
|
||||
}
|
||||
|
||||
console.log('\n=== All Tests Passed! ===');
|
||||
EOF
|
||||
|
||||
echo "=== Test files created in $TEST_DIR ==="
|
||||
|
||||
# Copy local package
|
||||
echo "=== Copying local package ==="
|
||||
mkdir -p node_modules/@ruvector
|
||||
cp -r /workspaces/ruvector/npm/core node_modules/@ruvector/
|
||||
|
||||
# Run test
|
||||
echo ""
|
||||
echo "=== Running test ==="
|
||||
node test.mjs
|
||||
|
||||
# Cleanup
|
||||
cd /
|
||||
rm -rf "$TEST_DIR"
|
||||
echo ""
|
||||
echo "=== Test completed successfully ==="
|
||||
47
vendor/ruvector/scripts/test/test-graph-cli.sh
vendored
Executable file
47
vendor/ruvector/scripts/test/test-graph-cli.sh
vendored
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
# Test script for RuVector Graph CLI commands
|
||||
|
||||
set -e
|
||||
|
||||
echo "============================================"
|
||||
echo "RuVector Graph CLI - Command Tests"
|
||||
echo "============================================"
|
||||
echo ""
|
||||
|
||||
# Build the CLI
|
||||
echo "Building CLI..."
|
||||
cargo build --package ruvector-cli --bin ruvector --quiet 2>&1 | grep -v "warning:" | head -5
|
||||
|
||||
CLI="./target/debug/ruvector"
|
||||
|
||||
echo ""
|
||||
echo "1. Testing main help..."
|
||||
$CLI --help | grep -A 2 "graph"
|
||||
|
||||
echo ""
|
||||
echo "2. Testing graph command help..."
|
||||
$CLI graph --help 2>&1 | head -20 || echo "Failed to show graph help"
|
||||
|
||||
echo ""
|
||||
echo "3. Testing graph create..."
|
||||
$CLI graph create --path /tmp/test-graph.db --name test --indexed 2>&1 | grep -v "warning:" || true
|
||||
|
||||
echo ""
|
||||
echo "4. Testing graph info..."
|
||||
$CLI graph info --db /tmp/test-graph.db 2>&1 | grep -v "warning:" || true
|
||||
|
||||
echo ""
|
||||
echo "5. Listing available graph commands..."
|
||||
echo " - create : Create new graph database"
|
||||
echo " - query : Execute Cypher queries"
|
||||
echo " - shell : Interactive REPL"
|
||||
echo " - import : Import from CSV/JSON/Cypher"
|
||||
echo " - export : Export to various formats"
|
||||
echo " - info : Show database statistics"
|
||||
echo " - benchmark : Run performance tests"
|
||||
echo " - serve : Start HTTP/gRPC server"
|
||||
|
||||
echo ""
|
||||
echo "============================================"
|
||||
echo "All graph commands are registered!"
|
||||
echo "============================================"
|
||||
176
vendor/ruvector/scripts/test/test-wasm.mjs
vendored
Executable file
176
vendor/ruvector/scripts/test/test-wasm.mjs
vendored
Executable file
@@ -0,0 +1,176 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* WASM Package Test Script
|
||||
* Tests ruvector-math-wasm and ruvector-attention-wasm in Node.js
|
||||
*/
|
||||
|
||||
import { readFileSync } from 'fs';
|
||||
import { dirname, join } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
console.log('🧪 Testing RuVector WASM Packages\n');
|
||||
|
||||
// ============================================================================
|
||||
// Test ruvector-math-wasm
|
||||
// ============================================================================
|
||||
async function testMathWasm() {
|
||||
console.log('📦 Testing ruvector-math-wasm...');
|
||||
|
||||
const pkgPath = join(__dirname, '../crates/ruvector-math-wasm/pkg');
|
||||
|
||||
try {
|
||||
// Load WASM module
|
||||
const wasmPath = join(pkgPath, 'ruvector_math_wasm_bg.wasm');
|
||||
const wasmBuffer = readFileSync(wasmPath);
|
||||
|
||||
// Import the JS bindings
|
||||
const mathWasm = await import(join(pkgPath, 'ruvector_math_wasm.js'));
|
||||
|
||||
// Initialize with WASM bytes
|
||||
await mathWasm.default(wasmBuffer);
|
||||
|
||||
// Test 1: Sliced Wasserstein Distance
|
||||
console.log(' ├─ Testing SlicedWasserstein...');
|
||||
const sw = new mathWasm.WasmSlicedWasserstein(100);
|
||||
|
||||
// Create test point clouds (3 points in 2D each)
|
||||
const source = new Float64Array([0, 0, 1, 0, 0, 1]);
|
||||
const target = new Float64Array([2, 0, 3, 0, 2, 1]);
|
||||
|
||||
const distance = sw.distance(source, target, 2);
|
||||
console.log(` │ Distance: ${distance.toFixed(4)}`);
|
||||
|
||||
if (distance > 0 && distance < 10) {
|
||||
console.log(' │ ✅ SlicedWasserstein works!');
|
||||
} else {
|
||||
throw new Error(`Unexpected distance: ${distance}`);
|
||||
}
|
||||
|
||||
// Test 2: Product Manifold
|
||||
console.log(' ├─ Testing ProductManifold...');
|
||||
const manifold = new mathWasm.WasmProductManifold(4, 2, 2); // E^4 x H^2 x S^2
|
||||
|
||||
// Create test points (8D total)
|
||||
const pointA = new Float64Array([1, 0, 0, 0, 0.1, 0.1, 1, 0]);
|
||||
const pointB = new Float64Array([0, 1, 0, 0, 0.2, 0.1, 0, 1]);
|
||||
|
||||
const manifoldDist = manifold.distance(pointA, pointB);
|
||||
console.log(` │ Manifold distance: ${manifoldDist.toFixed(4)}`);
|
||||
|
||||
if (manifoldDist > 0) {
|
||||
console.log(' │ ✅ ProductManifold works!');
|
||||
} else {
|
||||
throw new Error(`Unexpected manifold distance: ${manifoldDist}`);
|
||||
}
|
||||
|
||||
// Test 3: Spherical Space
|
||||
console.log(' ├─ Testing SphericalSpace...');
|
||||
const sphere = new mathWasm.WasmSphericalSpace(3);
|
||||
|
||||
const vecA = new Float64Array([1, 0, 0]);
|
||||
const vecB = new Float64Array([0, 1, 0]);
|
||||
|
||||
const sphereDist = sphere.distance(vecA, vecB);
|
||||
console.log(` │ Spherical distance: ${sphereDist.toFixed(4)} (expected: ~1.5708 = π/2)`);
|
||||
|
||||
if (Math.abs(sphereDist - Math.PI/2) < 0.01) {
|
||||
console.log(' │ ✅ SphericalSpace works!');
|
||||
} else {
|
||||
throw new Error(`Unexpected spherical distance: ${sphereDist}`);
|
||||
}
|
||||
|
||||
console.log(' └─ ✅ ruvector-math-wasm: All tests passed!\n');
|
||||
return true;
|
||||
|
||||
} catch (error) {
|
||||
console.error(' └─ ❌ Error:', error.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Test ruvector-attention-wasm
|
||||
// ============================================================================
|
||||
async function testAttentionWasm() {
|
||||
console.log('📦 Testing ruvector-attention-wasm...');
|
||||
|
||||
const pkgPath = join(__dirname, '../crates/ruvector-attention-wasm/pkg');
|
||||
|
||||
try {
|
||||
// Check if pkg exists (need to build first)
|
||||
const wasmPath = join(pkgPath, 'ruvector_attention_wasm_bg.wasm');
|
||||
|
||||
let wasmBuffer;
|
||||
try {
|
||||
wasmBuffer = readFileSync(wasmPath);
|
||||
} catch {
|
||||
console.log(' └─ ⚠️ Package not built. Building now...');
|
||||
const { execSync } = await import('child_process');
|
||||
execSync('wasm-pack build crates/ruvector-attention-wasm --target web --release', {
|
||||
cwd: join(__dirname, '..'),
|
||||
stdio: 'inherit'
|
||||
});
|
||||
wasmBuffer = readFileSync(wasmPath);
|
||||
}
|
||||
|
||||
// Import the JS bindings
|
||||
const attentionWasm = await import(join(pkgPath, 'ruvector_attention_wasm.js'));
|
||||
|
||||
// Initialize with WASM bytes
|
||||
await attentionWasm.default(wasmBuffer);
|
||||
|
||||
// Test 1: Scaled Dot Product Attention
|
||||
console.log(' ├─ Testing ScaledDotProductAttention...');
|
||||
|
||||
if (attentionWasm.WasmScaledDotProductAttention) {
|
||||
const attention = new attentionWasm.WasmScaledDotProductAttention(64);
|
||||
console.log(' │ ✅ ScaledDotProductAttention initialized');
|
||||
} else {
|
||||
console.log(' │ ⚠️ ScaledDotProductAttention not exported');
|
||||
}
|
||||
|
||||
// Test 2: Flash Attention (if available)
|
||||
console.log(' ├─ Testing FlashAttention...');
|
||||
|
||||
if (attentionWasm.WasmFlashAttention) {
|
||||
const flash = new attentionWasm.WasmFlashAttention(64, 64);
|
||||
console.log(' │ ✅ FlashAttention initialized');
|
||||
} else {
|
||||
console.log(' │ ⚠️ FlashAttention not exported');
|
||||
}
|
||||
|
||||
// List available exports
|
||||
console.log(' ├─ Available exports:');
|
||||
const exports = Object.keys(attentionWasm).filter(k => k.startsWith('Wasm'));
|
||||
exports.forEach(e => console.log(` │ - ${e}`));
|
||||
|
||||
console.log(' └─ ✅ ruvector-attention-wasm: Package loaded successfully!\n');
|
||||
return true;
|
||||
|
||||
} catch (error) {
|
||||
console.error(' └─ ❌ Error:', error.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Run all tests
|
||||
// ============================================================================
|
||||
async function main() {
|
||||
const results = {
|
||||
math: await testMathWasm(),
|
||||
attention: await testAttentionWasm()
|
||||
};
|
||||
|
||||
console.log('═══════════════════════════════════════');
|
||||
console.log('📊 Test Results:');
|
||||
console.log(` ruvector-math-wasm: ${results.math ? '✅ PASS' : '❌ FAIL'}`);
|
||||
console.log(` ruvector-attention-wasm: ${results.attention ? '✅ PASS' : '❌ FAIL'}`);
|
||||
console.log('═══════════════════════════════════════');
|
||||
|
||||
process.exit(results.math && results.attention ? 0 : 1);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
Reference in New Issue
Block a user