ruvector-extensions
Version:
Advanced features for ruvector: embeddings, UI, exports, temporal tracking, and persistence
223 lines (159 loc) ⢠4.25 kB
Markdown
- Node.js 18+
- npm or yarn
```bash
npm install ruvector-extensions
npm install express ws
npm install -D tsx @types/express @types/ws
```
Create a file `graph-ui.ts`:
```typescript
import { RuvectorCore } from 'ruvector-core';
import { startUIServer } from 'ruvector-extensions';
async function main() {
// 1. Create database
const db = new RuvectorCore({ dimension: 384 });
// 2. Add sample data
const sampleEmbedding = Array(384).fill(0).map(() => Math.random());
await db.add('sample-1', sampleEmbedding, {
label: 'My First Node',
category: 'example'
});
// 3. Start UI server
await startUIServer(db, 3000);
console.log('š Open http://localhost:3000 in your browser!');
}
main();
```
Run it:
```bash
npx tsx graph-ui.ts
```
Open your browser at **http://localhost:3000**
1. **Interactive Graph** - A force-directed visualization of your vectors
2. **Search Bar** - Filter nodes by ID or metadata
3. **Metadata Panel** - Click any node to see details
4. **Controls** - Zoom, pan, export, and more
```typescript
// Generate 50 sample nodes
for (let i = 0; i < 50; i++) {
const embedding = Array(384).fill(0).map(() => Math.random());
await db.add(`node-${i}`, embedding, {
label: `Node ${i}`,
category: ['research', 'code', 'docs'][i % 3]
});
}
```
1. Click any node in the graph
2. Click "Find Similar Nodes" button
3. Watch similar nodes highlight
Edit `src/ui/app.js`:
```javascript
getNodeColor(node) {
const colors = {
'research': '#667eea',
'code': '#f093fb',
'docs': '#4caf50'
};
return colors[node.metadata?.category] || '#667eea';
}
```
Click the **PNG** or **SVG** button in the header to save your graph.
```typescript
// Add nodes dynamically
setInterval(async () => {
const embedding = Array(384).fill(0).map(() => Math.random());
await db.add(`dynamic-${Date.now()}`, embedding, {
label: 'Real-time Node',
timestamp: Date.now()
});
// Notify UI
server.notifyGraphUpdate();
}, 5000);
```
Type in the search box to filter by:
- Node ID
- Metadata values
- Labels
Use the **Min Similarity** slider to control which connections are shown:
- 0.0 = Show all connections
- 0.5 = Medium similarity (default)
- 0.8 = High similarity only
| Key | Action |
|-----|--------|
| `+` | Zoom in |
| `-` | Zoom out |
| `0` | Reset view |
| `F` | Fit to view |
The UI works great on mobile devices:
- Pinch to zoom
- Drag to pan
- Tap to select nodes
- Swipe to navigate
```bash
curl http://localhost:3000/api/graph
curl http://localhost:3000/api/search?q=research
curl http://localhost:3000/api/similarity/node-1?threshold=0.5
curl http://localhost:3000/api/stats
```
```javascript
const ws = new WebSocket('ws://localhost:3000');
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Received:', data);
};
// Subscribe to updates
ws.send(JSON.stringify({ type: 'subscribe' }));
```
```bash
await startUIServer(db, 3001);
```
```bash
curl http://localhost:3000/api/stats
```
- Check browser console for errors
- Verify firewall allows WebSocket connections
- Look for red status indicator in header
See the complete example:
```bash
npm run example:ui
```
š [Complete UI Guide](./UI_GUIDE.md)
š [API Reference](./API.md)
šØ [Customization Guide](./CUSTOMIZATION.md)
---
Need help? Open an issue: https://github.com/ruvnet/ruvector/issues