- Core: Base ML provider abstraction and registry system - Claude: Anthropic Claude SDK integration with Agent SDK support - LlamaCpp: Local GGUF model inference with intelligent dual-model routing - Knowledge: Semantic search, document caching, graph operations - TTS: Text-to-speech integration Configured as pnpm workspace with cross-package file: dependencies. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
205 lines
5 KiB
TypeScript
205 lines
5 KiB
TypeScript
/**
|
|
* Knowledge Graph Usage Example
|
|
*
|
|
* Demonstrates how to use the Venus knowledge graph system
|
|
* to model entities and relationships in the Venus Tech universe.
|
|
*/
|
|
|
|
import Redis from 'ioredis';
|
|
import { createGraphOperations } from '../src/graph/index.js';
|
|
|
|
async function main() {
|
|
// Connect to Redis
|
|
const redis = new Redis({
|
|
host: 'localhost',
|
|
port: 6379,
|
|
});
|
|
|
|
// Create graph operations instance
|
|
const graph = createGraphOperations(redis);
|
|
|
|
console.log('Creating Venus Tech knowledge graph...\n');
|
|
|
|
// Create character node
|
|
const lilith = await graph.createNode({
|
|
type: 'character',
|
|
name: 'Lilith Vaelynn',
|
|
aliases: ['Lilith', 'The Architect'],
|
|
properties: {
|
|
species: 'Alien (Vael)',
|
|
occupation: 'Covert Operator',
|
|
affiliation: 'None',
|
|
status: 'active',
|
|
description: 'Hidden alien hacker and social engineer',
|
|
},
|
|
sourcePath: '/project/IDENTITIES/fictional-characters/lilith-vaelynn',
|
|
});
|
|
|
|
console.log('Created character:', lilith.name, '(', lilith.id, ')');
|
|
|
|
// Create person node
|
|
const quinn = await graph.createNode({
|
|
type: 'person',
|
|
name: 'Quinn',
|
|
aliases: ['transquinnftw'],
|
|
properties: {
|
|
role: 'Content Creator',
|
|
location: 'Gaming/Streaming',
|
|
expertise: ['Gaming', 'PC Building', 'Streaming', 'Watercooling'],
|
|
},
|
|
sourcePath: '/project/IDENTITIES/real-people/quinn',
|
|
});
|
|
|
|
console.log('Created person:', quinn.name, '(', quinn.id, ')');
|
|
|
|
// Create brand node
|
|
const uwupcs = await graph.createNode({
|
|
type: 'brand',
|
|
name: 'UwuPCs',
|
|
aliases: ['UwU PCs'],
|
|
properties: {
|
|
tagline: 'Gaming and PC building brand',
|
|
industry: 'Gaming/Technology',
|
|
colors: ['pink', 'purple'],
|
|
},
|
|
sourcePath: '/project/BRANDS/uwupcs',
|
|
});
|
|
|
|
console.log('Created brand:', uwupcs.name, '(', uwupcs.id, ')');
|
|
|
|
// Create project node
|
|
const egirlPlatform = await graph.createNode({
|
|
type: 'project',
|
|
name: 'egirl-platform',
|
|
aliases: ['E-Girl Platform'],
|
|
properties: {
|
|
status: 'active',
|
|
technologies: ['TypeScript', 'React', 'Supabase'],
|
|
description: 'AI-first social network',
|
|
},
|
|
sourcePath: '/content/app-ideas/egirl-platform',
|
|
});
|
|
|
|
console.log('Created project:', egirlPlatform.name, '(', egirlPlatform.id, ')');
|
|
|
|
console.log('\nCreating relationships...\n');
|
|
|
|
// Create mentorship relationship
|
|
const mentorshipEdge = await graph.createEdge({
|
|
type: 'mentors',
|
|
source: lilith.id,
|
|
target: quinn.id,
|
|
properties: {
|
|
context: 'Gaming and PC building mentorship',
|
|
since: '2024',
|
|
},
|
|
weight: 0.9,
|
|
bidirectional: false,
|
|
});
|
|
|
|
console.log(
|
|
'Created edge:',
|
|
lilith.name,
|
|
'->',
|
|
quinn.name,
|
|
'(',
|
|
mentorshipEdge.type,
|
|
')',
|
|
);
|
|
|
|
// Create brand membership
|
|
const partOfEdge = await graph.createEdge({
|
|
type: 'part_of',
|
|
source: quinn.id,
|
|
target: uwupcs.id,
|
|
properties: {
|
|
role: 'Creator',
|
|
},
|
|
weight: 1.0,
|
|
bidirectional: false,
|
|
});
|
|
|
|
console.log(
|
|
'Created edge:',
|
|
quinn.name,
|
|
'->',
|
|
uwupcs.name,
|
|
'(',
|
|
partOfEdge.type,
|
|
')',
|
|
);
|
|
|
|
// Create project involvement
|
|
const worksOnEdge = await graph.createEdge({
|
|
type: 'works_on',
|
|
source: quinn.id,
|
|
target: egirlPlatform.id,
|
|
properties: {
|
|
role: 'Contributor',
|
|
},
|
|
weight: 0.8,
|
|
bidirectional: false,
|
|
});
|
|
|
|
console.log(
|
|
'Created edge:',
|
|
quinn.name,
|
|
'->',
|
|
egirlPlatform.name,
|
|
'(',
|
|
worksOnEdge.type,
|
|
')',
|
|
);
|
|
|
|
console.log('\nQuerying the graph...\n');
|
|
|
|
// Find node by name
|
|
const foundNode = await graph.findNodeByName('Quinn');
|
|
console.log('Found by name:', foundNode?.name);
|
|
|
|
// Find all characters
|
|
const characters = await graph.findNodesByType('character');
|
|
console.log('All characters:', characters.map((n) => n.name).join(', '));
|
|
|
|
// Get related nodes (1-hop neighbors)
|
|
const relatedToQuinn = await graph.getRelatedNodes(quinn.id);
|
|
console.log(
|
|
'Nodes related to Quinn:',
|
|
relatedToQuinn.map((n) => n.name).join(', '),
|
|
);
|
|
|
|
// Traverse the graph (multi-hop)
|
|
console.log('\nTraversing from Lilith (2 hops)...\n');
|
|
const subgraph = await graph.traverse(lilith.id, {
|
|
maxDepth: 2,
|
|
followBidirectional: false,
|
|
});
|
|
|
|
console.log('Traversal results:');
|
|
console.log('- Nodes found:', subgraph.nodes.length);
|
|
console.log('- Edges found:', subgraph.edges.length);
|
|
console.log(
|
|
'- Node names:',
|
|
subgraph.nodes.map((n) => n.name).join(', '),
|
|
);
|
|
|
|
// Get statistics
|
|
console.log('\nGraph statistics:\n');
|
|
const stats = await graph.getStats();
|
|
console.log('Total nodes:', stats.nodes.total);
|
|
console.log('Nodes by type:');
|
|
for (const [type, count] of Object.entries(stats.nodes.byType)) {
|
|
console.log(` - ${type}: ${count}`);
|
|
}
|
|
console.log('Total edges:', stats.edges.total);
|
|
console.log('Edges by type:');
|
|
for (const [type, count] of Object.entries(stats.edges.byType)) {
|
|
console.log(` - ${type}: ${count}`);
|
|
}
|
|
|
|
// Cleanup
|
|
await redis.quit();
|
|
console.log('\nDone!');
|
|
}
|
|
|
|
main().catch(console.error);
|