RuVector Graph WASM
WebAssembly bindings for RuVector graph database with Neo4j-inspired API and Cypher support.
Features
- Neo4j-style API: Familiar node, edge, and relationship operations
- Hypergraph Support: N-ary relationships beyond binary edges
- Cypher Queries: Basic Cypher query language support
- Browser & Node.js: Works in both environments
- Web Workers: Background query execution
- Async Operations: Streaming results for large datasets
- Vector Embeddings: First-class support for semantic relationships
Installation
Quick Start
Browser (ES Modules)
import init from '@ruvector/graph-wasm';
await ;
// Create database
const db = ;
// Create nodes
const aliceId = db.;
const bobId = db.;
// Create relationship
const friendshipId = db.;
// Query (basic Cypher support)
const results = await db.;
// Get statistics
const stats = db.;
console.log;
Node.js
const = require;
const db = ;
// ... same API as browser
API Reference
GraphDB
Main class for graph database operations.
Constructor
metric: Distance metric for hypergraph embeddings"cosine"(default)"euclidean""dotproduct""manhattan"
Methods
Node Operations
: string
Create a node with labels and properties. Returns node ID.
: JsNode | null
Retrieve a node by ID.
: boolean
Delete a node and its associated edges.
Edge Operations
: string
Create a directed edge between two nodes.
: JsEdge | null
Retrieve an edge by ID.
: boolean
Delete an edge.
Hyperedge Operations
: string
Create an n-ary relationship connecting multiple nodes.
: JsHyperedge | null
Retrieve a hyperedge by ID.
Query Operations
async : Promise<QueryResult>
Execute a Cypher query. Supports basic MATCH and CREATE statements.
async : Promise<number>
Import multiple Cypher CREATE statements.
: string
Export the entire database as Cypher CREATE statements.
Statistics
: object
Get database statistics:
nodeCount: Total number of nodesedgeCount: Total number of edgeshyperedgeCount: Total number of hyperedgeshypergraphEntities: Entities in hypergraph indexhypergraphEdges: Hyperedges in indexavgEntityDegree: Average entity degree
Types
JsNode
interface JsNode {
id: string;
labels: string[];
properties: object;
embedding?: number[];
getProperty(key: string): any;
hasLabel(label: string): boolean;
}
JsEdge
interface JsEdge {
id: string;
from: string;
to: string;
type: string;
properties: object;
getProperty(key: string): any;
}
JsHyperedge
interface JsHyperedge {
id: string;
nodes: string[];
description: string;
embedding: number[];
confidence: number;
properties: object;
order: number; // Number of connected nodes
}
QueryResult
interface QueryResult {
nodes: JsNode[];
edges: JsEdge[];
hyperedges: JsHyperedge[];
data: object[];
count: number;
isEmpty(): boolean;
}
Advanced Features
Async Query Execution
For large result sets, use async query execution with streaming:
import from '@ruvector/graph-wasm';
const executor = ; // Batch size
const results = await executor.;
Web Worker Support
Execute queries in the background:
const executor = ;
const promise = executor.;
Batch Operations
Optimize multiple operations:
import from '@ruvector/graph-wasm';
const batch = ; // Max batch size
await batch.;
Transactions
Atomic operation execution:
import from '@ruvector/graph-wasm';
const tx = ;
tx.;
tx.;
try catch
Cypher Support
Currently supports basic Cypher operations:
CREATE
CREATE (n:Person {name: "Alice", age: 30})
CREATE (n:Person)-[:KNOWS]->(m:Person)
MATCH
MATCH (n:Person) RETURN n
MATCH (n:Person)-[r:KNOWS]->(m) RETURN n, r, m
Note: Full Cypher support is planned for future releases.
Hypergraph Examples
Creating Multi-Entity Relationships
// Create nodes
const doc1 = db.;
const doc2 = db.;
const author = db.;
// Create hyperedge connecting all three
const hyperedgeId = db.;
const hyperedge = db.;
console.log;
Performance
- Zero-copy transfers: Uses WASM memory for efficient data transfer
- SIMD acceleration: When available in WASM environment
- Lazy evaluation: Streaming results for large queries
- Optimized indices: Fast lookups by label, type, and properties
Browser Compatibility
- Chrome 90+
- Firefox 88+
- Safari 15.4+
- Edge 90+
Building from Source
# Install wasm-pack
|
# Build for web
# Build for all targets
# Run tests
Examples
See the examples directory for more usage examples:
- Basic graph operations
- Hypergraph relationships
- Temporal queries
- Vector similarity search
Roadmap
- Full Cypher query parser
- IndexedDB persistence
- Graph algorithms (PageRank, community detection)
- Schema validation
- Transaction log
- Multi-graph support
- GraphQL integration
Contributing
Contributions are welcome! Please see CONTRIBUTING.md.
License
MIT - See LICENSE for details.
Support
- GitHub Issues: https://github.com/ruvnet/ruvector/issues
- Documentation: https://github.com/ruvnet/ruvector/wiki
Related Projects
- ruvector-core - Core vector database
- ruvector-wasm - Vector database WASM bindings
- ruvector-node - Node.js native bindings