rust-kgdb 0.6.4 → 0.6.5
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.
- package/examples/core-concepts-demo.ts +50 -35
- package/examples/datalog-example.ts +246 -339
- package/examples/fraud-detection-agent.js +23 -36
- package/examples/hypermind-fraud-underwriter.ts +54 -51
- package/examples/underwriting-agent.js +16 -20
- package/hypermind-agent.js +984 -2643
- package/package.json +1 -1
- package/rust-kgdb-napi.darwin-x64.node +0 -0
|
@@ -18,9 +18,12 @@
|
|
|
18
18
|
|
|
19
19
|
import {
|
|
20
20
|
GraphDB,
|
|
21
|
-
|
|
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
|
|
248
|
+
const program = new DatalogProgram();
|
|
246
249
|
|
|
247
|
-
// Add facts
|
|
250
|
+
// Add facts using JSON format
|
|
248
251
|
console.log(' Facts (parent relationship):');
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
265
|
-
{ predicate: '
|
|
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
|
-
|
|
270
|
-
{ predicate: '
|
|
271
|
-
|
|
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
|
|
276
|
-
console.log(` Semi-naive evaluation completed
|
|
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 =
|
|
281
|
-
|
|
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
|
|
284
|
-
console.log(` -
|
|
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 {
|
|
431
|
+
import { HyperMindAgent } from 'rust-kgdb';
|
|
422
432
|
|
|
423
|
-
|
|
433
|
+
// Spawn a HyperMind agent with typed tools
|
|
434
|
+
const agent = await HyperMindAgent.spawn({
|
|
424
435
|
name: 'fraud-detector',
|
|
425
|
-
model:
|
|
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
|
-
|
|
432
|
-
|
|
433
|
-
wasmSandbox: true,
|
|
442
|
+
endpoint: 'http://localhost:30080', // K8s cluster endpoint
|
|
443
|
+
tracing: true,
|
|
434
444
|
});
|
|
435
445
|
|
|
436
|
-
|
|
437
|
-
await agent.
|
|
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
|
}
|