ruvector-extensions
Version:
Advanced features for ruvector: embeddings, UI, exports, temporal tracking, and persistence
321 lines (235 loc) ⢠6.96 kB
Markdown
Interactive web-based visualization for exploring vector embeddings as a force-directed graph.
- š **Interactive force-directed graph** with D3.js
- š±ļø **Drag, zoom, and pan** controls
- š **Search and filter** nodes by metadata
- šÆ **Similarity queries** - click to find similar nodes
- š **Metadata panel** with detailed node information
- ā” **Real-time updates** via WebSocket
- šø **Export** as PNG or SVG
- š± **Responsive design** for mobile devices
- šØ **Color-coded** nodes by category
- š **Live statistics** dashboard
```bash
npm install ruvector-extensions express ws
```
```typescript
import { RuvectorCore } from 'ruvector-core';
import { startUIServer } from 'ruvector-extensions/ui-server';
// Initialize database
const db = new RuvectorCore({ dimension: 384 });
// Add some vectors
await db.add('doc1', embedding1, { label: 'Document 1', category: 'research' });
await db.add('doc2', embedding2, { label: 'Document 2', category: 'code' });
// Start UI server on port 3000
const server = await startUIServer(db, 3000);
// Open browser at http://localhost:3000
```
```bash
npm run example:ui
```
Then navigate to `http://localhost:3000` in your browser.
- Force-directed graph with interactive nodes
- Sidebar with search, filters, and statistics
- Real-time connection status indicator
1. **Search**: Type in search box to filter nodes
2. **Select**: Click any node to view metadata
3. **Similarity**: Click "Find Similar Nodes" or double-click
4. **Export**: Save visualization as PNG or SVG
5. **Mobile**: Fully responsive on all devices
- **Click node**: Select and show metadata
- **Double-click node**: Find similar nodes
- **Drag node**: Reposition in graph
- **Scroll/Pinch**: Zoom in/out
- **Drag background**: Pan view
- **Search**: Filter nodes by ID or metadata
- **Similarity slider**: Adjust threshold (0-1)
- **Find Similar**: Query similar nodes
- **Export PNG/SVG**: Save visualization
- **Reset View**: Return to default zoom
- **Zoom +/-**: Zoom controls
- **Fit View**: Auto-fit graph to window
## š API Reference
### REST Endpoints
```bash
# Get graph data
GET /api/graph?max=100
GET /api/search?q=query
GET /api/similarity/:nodeId?threshold=0.5&limit=10
GET /api/nodes/:nodeId
POST /api/nodes
{
"id": "node-123",
"embedding": [0.1, 0.2, ...],
"metadata": { "label": "Example" }
}
GET /api/stats
GET /health
```
**Client ā Server:**
```javascript
// Subscribe to updates
{ "type": "subscribe" }
// Request graph
{ "type": "request_graph", "maxNodes": 100 }
// Query similarity
{
"type": "similarity_query",
"nodeId": "node-123",
"threshold": 0.5,
"limit": 10
}
```
**Server ā Client:**
```javascript
// Graph data
{ "type": "graph_data", "payload": { "nodes": [...], "links": [...] }}
// Node added
{ "type": "node_added", "payload": { "id": "...", "metadata": {...} }}
// Similarity results
{ "type": "similarity_result", "payload": { "nodeId": "...", "similar": [...] }}
```
Customize in `/src/ui/app.js`:
```javascript
getNodeColor(node) {
const colors = {
'research': '#667eea',
'code': '#f093fb',
'docs': '#4caf50',
'test': '#ff9800'
};
return colors[node.metadata?.category] || '#667eea';
}
```
Edit `/src/ui/styles.css`:
```css
:root {
--primary-color:
--secondary-color:
--accent-color:
}
```
Adjust physics in `/src/ui/app.js`:
```javascript
this.simulation
.force('link', d3.forceLink().distance(100))
.force('charge', d3.forceManyBody().strength(-300))
.force('collision', d3.forceCollide().radius(30));
```
```typescript
import { UIServer } from 'ruvector-extensions/ui-server';
const server = new UIServer(db, 3000);
// Custom middleware
server.app.use('/custom', customRouter);
await server.start();
```
```typescript
// Notify clients of changes
server.notifyGraphUpdate();
// Broadcast custom event
server.broadcast({
type: 'custom_event',
payload: { data: 'value' }
});
```
The UI is fully optimized for mobile:
- ā
Touch gestures (pinch to zoom)
- ā
Responsive sidebar layout
- ā
Simplified mobile controls
- ā
Optimized performance
## š Performance
### Large Graphs (1000+ nodes)
- Limit visible nodes to 500
- Use clustering for better performance
- Reduce force simulation iterations
- Hide labels at low zoom levels
### Optimizations
```javascript
// Reduce node limit
const maxNodes = 500;
// Faster convergence
this.simulation.alpha(0.5).alphaDecay(0.05);
// Conditional labels
label.style('display', d => zoom.scale() > 1.5 ? 'block' : 'none');
```
| Browser | Version | Status |
|---------|---------|--------|
| Chrome | 90+ | ā
Full |
| Firefox | 88+ | ā
Full |
| Safari | 14+ | ā
Full |
| Edge | 90+ | ā
Full |
| Mobile Safari | 14+ | ā
Full |
| Chrome Mobile | 90+ | ā
Full |
- [UI Guide](./docs/UI_GUIDE.md) - Complete documentation
- [API Reference](./docs/API.md) - REST and WebSocket API
- [Examples](./src/examples/) - Usage examples
- Check console for errors
- Verify database has data: `GET /api/stats`
- Check WebSocket connection status
- Reduce max nodes in sidebar
- Clear filters
- Check network tab for slow API calls
- Check firewall settings
- Verify port is accessible
- Look for server errors
```
src/
āāā ui/
ā āāā index.html
ā āāā app.js
ā āāā styles.css
āāā ui-server.ts
āāā examples/
āāā ui-example.ts
```
Contributions welcome! Please:
1. Fork the repository
2. Create a feature branch
3. Add tests for new features
4. Submit a pull request
MIT License - see [LICENSE](../../LICENSE) file
- [D3.js](https://d3js.org/) - Graph visualization
- [Express](https://expressjs.com/) - Web server
- [WebSocket](https://github.com/websockets/ws) - Real-time updates
- š [Documentation](https://github.com/ruvnet/ruvector)
- š [Issues](https://github.com/ruvnet/ruvector/issues)
- š¬ [Discussions](https://github.com/ruvnet/ruvector/discussions)
---
Built with ā¤ļø by the [ruv.io](https://ruv.io) team