6.5 KiB
6.5 KiB
RuVector Graph WASM - Setup Complete
Created Files
Rust Crate (/home/user/ruvector/crates/ruvector-graph-wasm/)
-
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
-
src/lib.rs - Main GraphDB implementation
GraphDBclass with Neo4j-inspired API- Node, edge, and hyperedge operations
- Basic Cypher query support
- Import/export functionality
- Statistics and monitoring
-
src/types.rs - JavaScript-friendly type conversions
JsNode,JsEdge,JsHyperedgewrappersQueryResultfor query responses- Type conversion utilities
- Error handling types
-
src/async_ops.rs - Async operations
AsyncQueryExecutorfor streaming resultsAsyncTransactionfor atomic operationsBatchOperationsfor bulk processingResultStreamfor chunked data
-
build.sh - Build script for multiple targets
- Web (ES modules)
- Node.js
- Bundler (Webpack, Rollup, etc.)
-
README.md - Comprehensive documentation
- API reference
- Usage examples
- Browser compatibility
- Build instructions
NPM Package (/home/user/ruvector/npm/packages/graph-wasm/)
-
package.json - NPM package configuration
- Build scripts for all targets
- Package metadata
- Publishing configuration
-
index.js - Package entry point
- Re-exports from generated WASM
-
index.d.ts - TypeScript definitions
- Full type definitions for all classes
- Interface definitions
- Enum types
Examples (/home/user/ruvector/examples/)
- 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
- Install Rust toolchain:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Install wasm-pack:
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- 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
-
Install WASM toolchain:
rustup target add wasm32-unknown-unknown curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -
Build the package:
cd /home/user/ruvector/crates/ruvector-graph-wasm ./build.sh -
Test in browser:
# Serve the examples directory python3 -m http.server 8000 # Open http://localhost:8000/examples/graph_wasm_usage.html -
Publish to NPM (when ready):
cd /home/user/ruvector/npm/packages/graph-wasm npm publish --access public
Support
- GitHub: https://github.com/ruvnet/ruvector
- Issues: https://github.com/ruvnet/ruvector/issues
- Docs: https://github.com/ruvnet/ruvector/wiki
Created: 2025-11-25 Version: 0.1.1 License: MIT