rust-kgdb 0.6.4 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,9 +18,12 @@
18
18
 
19
19
  import {
20
20
  GraphDB,
21
- DatalogEngine,
21
+ DatalogProgram,
22
+ evaluateDatalog,
23
+ queryDatalog,
22
24
  EmbeddingService,
23
25
  GraphFrame,
26
+ HyperMindAgent,
24
27
  } from 'rust-kgdb';
25
28
 
26
29
  // =============================================================================
@@ -242,46 +245,53 @@ function demoDatalogReasoning(): void {
242
245
  console.log('='.repeat(70));
243
246
  console.log();
244
247
 
245
- const engine = new DatalogEngine();
248
+ const program = new DatalogProgram();
246
249
 
247
- // Add facts
250
+ // Add facts using JSON format
248
251
  console.log(' Facts (parent relationship):');
249
- engine.addFact('parent', ['alice', 'bob']);
250
- engine.addFact('parent', ['bob', 'charlie']);
251
- engine.addFact('parent', ['charlie', 'david']);
252
+ program.addFact(JSON.stringify({ predicate: 'parent', terms: ['alice', 'bob'] }));
253
+ program.addFact(JSON.stringify({ predicate: 'parent', terms: ['bob', 'charlie'] }));
254
+ program.addFact(JSON.stringify({ predicate: 'parent', terms: ['charlie', 'david'] }));
252
255
  console.log(' parent(alice, bob)');
253
256
  console.log(' parent(bob, charlie)');
254
257
  console.log(' parent(charlie, david)');
258
+ console.log(` Total facts: ${program.factCount()}`);
255
259
  console.log();
256
260
 
257
- // Add recursive rules
261
+ // Add recursive rules using JSON format
258
262
  console.log(' Rules (transitive closure):');
259
263
  console.log(' ancestor(X, Y) :- parent(X, Y) % base case');
260
264
  console.log(' ancestor(X, Z) :- parent(X, Y), ancestor(Y, Z) % recursive');
261
265
  console.log();
262
266
 
263
- // Base case
264
- engine.addRule('ancestor', ['X', 'Y'], [
265
- { predicate: 'parent', args: ['X', 'Y'] }
266
- ]);
267
+ // Base case: ancestor(X, Y) :- parent(X, Y)
268
+ program.addRule(JSON.stringify({
269
+ head: { predicate: 'ancestor', terms: ['X', 'Y'] },
270
+ body: [{ predicate: 'parent', terms: ['X', 'Y'] }]
271
+ }));
267
272
 
268
- // Recursive case
269
- engine.addRule('ancestor', ['X', 'Z'], [
270
- { predicate: 'parent', args: ['X', 'Y'] },
271
- { predicate: 'ancestor', args: ['Y', 'Z'] }
272
- ]);
273
+ // Recursive case: ancestor(X, Z) :- parent(X, Y), ancestor(Y, Z)
274
+ program.addRule(JSON.stringify({
275
+ head: { predicate: 'ancestor', terms: ['X', 'Z'] },
276
+ body: [
277
+ { predicate: 'parent', terms: ['X', 'Y'] },
278
+ { predicate: 'ancestor', terms: ['Y', 'Z'] }
279
+ ]
280
+ }));
273
281
 
274
- // Evaluate
275
- const iterations = engine.evaluateSemiNaive();
276
- console.log(` Semi-naive evaluation completed in ${iterations} iterations`);
282
+ // Evaluate using semi-naive algorithm
283
+ const evalResult = evaluateDatalog(program);
284
+ console.log(` Semi-naive evaluation completed`);
285
+ console.log(` Result: ${evalResult}`);
277
286
  console.log();
278
287
 
279
- // Query
280
- const results = engine.query('ancestor', ['alice', '?descendant']);
281
- console.log(' Query: ancestor(alice, ?descendant)');
288
+ // Query ancestors
289
+ const results = queryDatalog(program, 'ancestor');
290
+ const parsed = JSON.parse(results);
291
+ console.log(' Query: ancestor(?who, ?descendant)');
282
292
  console.log(' Results:');
283
- for (const r of results) {
284
- console.log(` - alice is ancestor of ${r.descendant}`);
293
+ for (const r of parsed) {
294
+ console.log(` - ${r.terms[0]} is ancestor of ${r.terms[1]}`);
285
295
  }
286
296
  console.log();
287
297
  }
@@ -418,23 +428,28 @@ function demoHyperMindAgents(): void {
418
428
  console.log(' Agent Creation (TypeScript):');
419
429
  console.log(' ------------------------------');
420
430
  console.log(`
421
- import { spawn, AgentSpec, Model } from 'rust-kgdb';
431
+ import { HyperMindAgent } from 'rust-kgdb';
422
432
 
423
- const agent = await spawn({
433
+ // Spawn a HyperMind agent with typed tools
434
+ const agent = await HyperMindAgent.spawn({
424
435
  name: 'fraud-detector',
425
- model: Model.Claude('claude-3-opus'),
436
+ model: 'claude-sonnet-4', // or 'gpt-4o', 'claude-opus-4', 'mock'
426
437
  tools: [
427
- 'kg.sparql.query',
428
- 'kg.motif.find',
429
- 'kg.datalog.apply',
438
+ 'kg.sparql.query', // Query -> BindingSet
439
+ 'kg.motif.find', // Graph -> PatternSet
440
+ 'kg.datalog.apply', // Rules -> InferredFacts
430
441
  ],
431
- maxIterations: 10,
432
- tracingEnabled: true,
433
- wasmSandbox: true,
442
+ endpoint: 'http://localhost:30080', // K8s cluster endpoint
443
+ tracing: true,
434
444
  });
435
445
 
436
- const result = await agent.call('Find circular payments');
437
- await agent.exportTrace('audit.json');
446
+ // Execute with natural language
447
+ const result = await agent.call('Find circular payment patterns');
448
+ console.log(result.sparql); // Generated SPARQL
449
+ console.log(result.results); // Query results
450
+
451
+ // Get execution trace for audit
452
+ const trace = agent.getTrace();
438
453
  `);
439
454
  console.log();
440
455
  }