rust-kgdb 0.6.3 → 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/README.md CHANGED
@@ -205,33 +205,48 @@ agent.chat("What fraud patterns did we find with Provider P001?")
205
205
  // Cost: Re-run entire fraud detection pipeline ($5 in API calls, 30 seconds)
206
206
  ```
207
207
 
208
- **With Memory Hypergraph** (rust-kgdb):
208
+ **With Memory Hypergraph** (rust-kgdb HyperMind Framework):
209
209
  ```javascript
210
- // Memories are automatically linked to KG entities
211
- const memories = await agent.recall("Provider P001 fraud", 10)
212
- // Returns: Episodes 001, 002, 003 - all linked to Provider:P001 in KG
210
+ // HyperMind API: Recall memories with KG context (typed, not raw SPARQL)
211
+ const enrichedMemories = await agent.recallWithKG({
212
+ query: "Provider P001 fraud",
213
+ kgFilter: { predicate: ":amount", operator: ">", value: 25000 },
214
+ limit: 10
215
+ })
213
216
 
214
- // Even better: SPARQL traverses BOTH memory and KG
215
- const results = db.querySelect(`
216
- PREFIX am: <https://gonnect.ai/ontology/agent-memory#>
217
- PREFIX : <http://insurance.org/>
218
-
219
- SELECT ?episode ?finding ?claimAmount WHERE {
220
- # Search memory graph
221
- GRAPH <https://gonnect.ai/memory/> {
222
- ?episode a am:Episode ;
223
- am:prompt ?finding .
224
- ?edge am:source ?episode ;
225
- am:target ?provider .
226
- }
227
- # Join with knowledge graph
228
- ?claim :provider ?provider ;
229
- :amount ?claimAmount .
230
- FILTER(?claimAmount > 25000)
217
+ // Returns typed results:
218
+ // {
219
+ // episode: "Episode:001",
220
+ // finding: "Fraud ring detected in Provider P001",
221
+ // kgContext: {
222
+ // provider: "Provider:P001",
223
+ // claims: [{ id: "Claim:C123", amount: 50000 }],
224
+ // riskScore: 0.87
225
+ // },
226
+ // semanticHash: "semhash:fraud-provider-p001-ring-detection"
227
+ // }
228
+
229
+ // Framework generates optimized SPARQL internally:
230
+ // - Joins memory graph with KG automatically
231
+ // - Applies semantic hashing for deduplication
232
+ // - Returns typed objects, not raw bindings
233
+ ```
234
+
235
+ **Under the hood**, HyperMind generates the SPARQL:
236
+ ```sparql
237
+ PREFIX am: <https://gonnect.ai/ontology/agent-memory#>
238
+ PREFIX : <http://insurance.org/>
239
+
240
+ SELECT ?episode ?finding ?claimAmount WHERE {
241
+ GRAPH <https://gonnect.ai/memory/> {
242
+ ?episode a am:Episode ; am:prompt ?finding .
243
+ ?edge am:source ?episode ; am:target ?provider .
231
244
  }
232
- `)
233
- // Returns: Episode findings + actual claim data - in ONE query!
245
+ ?claim :provider ?provider ; :amount ?claimAmount .
246
+ FILTER(?claimAmount > 25000)
247
+ }
234
248
  ```
249
+ *You never write this - the typed API builds it for you.*
235
250
 
236
251
  ### Rolling Context Window
237
252
 
@@ -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
  }