Files
wifi-densepose/docs/gnn/graph-wasm-setup.md
ruv d803bfe2b1 Squashed 'vendor/ruvector/' content from commit b64c2172
git-subtree-dir: vendor/ruvector
git-subtree-split: b64c21726f2bb37286d9ee36a7869fef60cc6900
2026-02-28 14:39:40 -05:00

6.5 KiB

RuVector Graph WASM - Setup Complete

Created Files

Rust Crate (/home/user/ruvector/crates/ruvector-graph-wasm/)

  1. Cargo.toml - WASM crate configuration with dependencies

    • wasm-bindgen for JavaScript bindings
    • serde-wasm-bindgen for type conversions
    • ruvector-core for hypergraph functionality
    • Optimized release profile for small WASM size
  2. src/lib.rs - Main GraphDB implementation

    • GraphDB class with Neo4j-inspired API
    • Node, edge, and hyperedge operations
    • Basic Cypher query support
    • Import/export functionality
    • Statistics and monitoring
  3. src/types.rs - JavaScript-friendly type conversions

    • JsNode, JsEdge, JsHyperedge wrappers
    • QueryResult for query responses
    • Type conversion utilities
    • Error handling types
  4. src/async_ops.rs - Async operations

    • AsyncQueryExecutor for streaming results
    • AsyncTransaction for atomic operations
    • BatchOperations for bulk processing
    • ResultStream for chunked data
  5. build.sh - Build script for multiple targets

    • Web (ES modules)
    • Node.js
    • Bundler (Webpack, Rollup, etc.)
  6. README.md - Comprehensive documentation

    • API reference
    • Usage examples
    • Browser compatibility
    • Build instructions

NPM Package (/home/user/ruvector/npm/packages/graph-wasm/)

  1. package.json - NPM package configuration

    • Build scripts for all targets
    • Package metadata
    • Publishing configuration
  2. index.js - Package entry point

    • Re-exports from generated WASM
  3. index.d.ts - TypeScript definitions

    • Full type definitions for all classes
    • Interface definitions
    • Enum types

Examples (/home/user/ruvector/examples/)

  1. graph_wasm_usage.html - Interactive demo
    • Live graph database operations
    • Visual statistics display
    • Sample graph creation
    • Hypergraph examples

API Overview

Core Classes

GraphDB

const db = new GraphDB('cosine');
db.createNode(labels, properties)
db.createEdge(from, to, type, properties)
db.createHyperedge(nodes, description, embedding?, confidence?)
await db.query(cypherQuery)
db.stats()

JsNode

node.id
node.labels
node.properties
node.getProperty(key)
node.hasLabel(label)

JsEdge

edge.id
edge.from
edge.to
edge.type
edge.properties

JsHyperedge

hyperedge.id
hyperedge.nodes
hyperedge.description
hyperedge.embedding
hyperedge.confidence
hyperedge.order

Advanced Features

Async Query Execution

const executor = new AsyncQueryExecutor(100);
await executor.executeStreaming(query);

Transactions

const tx = new AsyncTransaction();
tx.addOperation('CREATE (n:Person {name: "Alice"})');
await tx.commit();

Batch Operations

const batch = new BatchOperations(1000);
await batch.executeBatch(statements);

Building

Prerequisites

  1. Install Rust toolchain:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. Install wasm-pack:
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
  1. Add WASM target:
rustup target add wasm32-unknown-unknown

Build Commands

Build for Web (default)

cd /home/user/ruvector/crates/ruvector-graph-wasm
./build.sh

Or using npm:

cd /home/user/ruvector/npm/packages/graph-wasm
npm run build

Build for Node.js

npm run build:node

Build for Bundlers

npm run build:bundler

Build All Targets

npm run build:all

Using in Projects

Browser (ES Modules)

<script type="module">
import init, { GraphDB } from './ruvector_graph_wasm.js';

await init();
const db = new GraphDB('cosine');
// Use the database...
</script>

Node.js

const { GraphDB } = require('@ruvector/graph-wasm/node');
const db = new GraphDB('cosine');

Bundlers (Webpack, Vite, etc.)

import { GraphDB } from '@ruvector/graph-wasm';
const db = new GraphDB('cosine');

Features Implemented

  • Node CRUD operations
  • Edge CRUD operations
  • Hyperedge support (n-ary relationships)
  • Basic Cypher query parsing
  • Import/export to Cypher
  • Vector embeddings support
  • Database statistics
  • Async operations
  • Transaction support
  • Batch operations
  • TypeScript definitions
  • Browser compatibility
  • Node.js compatibility
  • Web Worker support (prepared)

Roadmap

  • Full Cypher parser implementation
  • IndexedDB persistence
  • Graph algorithms (PageRank, shortest path)
  • Advanced query optimization
  • Schema validation
  • Full-text search
  • Geospatial queries
  • Temporal graph queries

Integration with RuVector

This WASM binding leverages RuVector's hypergraph implementation from ruvector-core:

  • HypergraphIndex: Bipartite graph storage for n-ary relationships
  • Hyperedge: Multi-entity relationships with embeddings
  • TemporalHyperedge: Time-aware relationships
  • CausalMemory: Causal relationship tracking
  • Distance Metrics: Cosine, Euclidean, DotProduct, Manhattan

File Locations

/home/user/ruvector/
├── crates/
│   └── ruvector-graph-wasm/
│       ├── Cargo.toml
│       ├── README.md
│       ├── build.sh
│       └── src/
│           ├── lib.rs
│           ├── types.rs
│           └── async_ops.rs
├── npm/
│   └── packages/
│       └── graph-wasm/
│           ├── package.json
│           ├── index.js
│           └── index.d.ts
├── examples/
│   └── graph_wasm_usage.html
└── docs/
    └── graph-wasm-setup.md (this file)

Next Steps

  1. Install WASM toolchain:

    rustup target add wasm32-unknown-unknown
    curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
    
  2. Build the package:

    cd /home/user/ruvector/crates/ruvector-graph-wasm
    ./build.sh
    
  3. Test in browser:

    # Serve the examples directory
    python3 -m http.server 8000
    # Open http://localhost:8000/examples/graph_wasm_usage.html
    
  4. Publish to NPM (when ready):

    cd /home/user/ruvector/npm/packages/graph-wasm
    npm publish --access public
    

Support


Created: 2025-11-25 Version: 0.1.1 License: MIT