rust-kgdb 0.3.5 → 0.3.7
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 +39 -13
- package/index.d.ts +317 -0
- package/index.js +15 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -830,31 +830,57 @@ HyperMind was benchmarked using the **LUBM (Lehigh University Benchmark)** - the
|
|
|
830
830
|
|
|
831
831
|
**Benchmark Configuration:**
|
|
832
832
|
- **Dataset**: LUBM(1) - 3,272 triples (1 university)
|
|
833
|
-
- **Queries**: 12 LUBM queries
|
|
834
|
-
- **LLM Models**: Claude Sonnet 4, GPT-4o
|
|
835
|
-
- **
|
|
833
|
+
- **Queries**: 12 LUBM-style NL-to-SPARQL queries
|
|
834
|
+
- **LLM Models**: Claude Sonnet 4 (`claude-sonnet-4-20250514`), GPT-4o
|
|
835
|
+
- **Infrastructure**: rust-kgdb K8s cluster (1 coordinator + 3 executors)
|
|
836
|
+
- **Date**: December 12, 2025
|
|
837
|
+
|
|
838
|
+
**Benchmark Results (Actual Run Data):**
|
|
836
839
|
|
|
837
840
|
| Metric | Claude Sonnet 4 | GPT-4o |
|
|
838
841
|
|--------|-----------------|--------|
|
|
839
842
|
| **Syntax Success (Raw LLM)** | 0% (0/12) | 100% (12/12) |
|
|
840
843
|
| **Syntax Success (HyperMind)** | **92% (11/12)** | 75% (9/12) |
|
|
841
844
|
| **Type Errors Caught** | 1 | 3 |
|
|
842
|
-
| **
|
|
845
|
+
| **Avg Latency (Raw)** | 167ms | 1,885ms |
|
|
846
|
+
| **Avg Latency (HyperMind)** | 6,230ms | 2,998ms |
|
|
843
847
|
|
|
844
|
-
**
|
|
848
|
+
**Example LUBM Queries We Ran:**
|
|
849
|
+
|
|
850
|
+
| # | Natural Language Question | Difficulty |
|
|
851
|
+
|---|--------------------------|------------|
|
|
852
|
+
| Q1 | "Find all professors in the university database" | Easy |
|
|
853
|
+
| Q3 | "How many courses are offered?" | Easy (COUNT) |
|
|
854
|
+
| Q5 | "List professors and the courses they teach" | Medium (JOIN) |
|
|
855
|
+
| Q8 | "Find the average credit hours for graduate courses" | Medium (AVG) |
|
|
856
|
+
| Q9 | "Find graduate students whose advisors research ML" | Hard (multi-hop) |
|
|
857
|
+
| Q12 | "Find pairs of students sharing advisor and courses" | Hard (complex) |
|
|
858
|
+
|
|
859
|
+
**Type Errors Caught at Planning Time:**
|
|
860
|
+
|
|
861
|
+
```
|
|
862
|
+
Test 8 (Claude): "TYPE ERROR: AVG aggregation type mismatch"
|
|
863
|
+
Test 9 (GPT-4o): "TYPE ERROR: expected String, found BindingSet"
|
|
864
|
+
Test 10 (GPT-4o): "TYPE ERROR: composition rejected"
|
|
865
|
+
Test 12 (GPT-4o): "NO QUERY GENERATED: type check failed"
|
|
866
|
+
```
|
|
867
|
+
|
|
868
|
+
**Root Cause Analysis:**
|
|
845
869
|
|
|
846
|
-
1. **
|
|
870
|
+
1. **Claude Raw 0%**: Claude's raw responses include markdown formatting (triple backticks: \`\`\`sparql) which fails SPARQL validation. HyperMind's typed tool definitions force structured JSON output.
|
|
847
871
|
|
|
848
|
-
2. **
|
|
872
|
+
2. **GPT-4o 75% (not 100%)**: The 25% "failures" are actually **type system victories**—the framework correctly caught queries that would have failed at runtime due to type mismatches.
|
|
849
873
|
|
|
850
|
-
3. **
|
|
874
|
+
3. **GPT-4o Intelligent Tool Selection**: On complex pattern queries (Q5, Q8), GPT-4o chose `kg.motif.find` over SPARQL, demonstrating HyperMind's tool discovery working correctly.
|
|
875
|
+
|
|
876
|
+
**Key Findings:**
|
|
851
877
|
|
|
852
|
-
**
|
|
853
|
-
- **
|
|
854
|
-
|
|
855
|
-
|
|
878
|
+
1. **+92% syntax improvement for Claude** - from 0% to 92% by forcing structured output
|
|
879
|
+
2. **Compile-time type safety** - 4 type errors caught before execution (would have been runtime failures)
|
|
880
|
+
3. **Intelligent tool selection** - LLM autonomously chose appropriate tools (SPARQL vs motif)
|
|
881
|
+
4. **Full provenance** - every plan step recorded for auditability
|
|
856
882
|
|
|
857
|
-
**LUBM Reference**: [Lehigh University Benchmark](http://swat.cse.lehigh.edu/projects/lubm/) -
|
|
883
|
+
**LUBM Reference**: [Lehigh University Benchmark](http://swat.cse.lehigh.edu/projects/lubm/) - W3C standardized Semantic Web database benchmark
|
|
858
884
|
|
|
859
885
|
### SDK Benchmark Results
|
|
860
886
|
|
package/index.d.ts
CHANGED
|
@@ -424,3 +424,320 @@ export function evaluateDatalog(program: DatalogProgram): string
|
|
|
424
424
|
* @returns JSON array of matching facts
|
|
425
425
|
*/
|
|
426
426
|
export function queryDatalog(program: DatalogProgram, predicate: string): string
|
|
427
|
+
|
|
428
|
+
// ==============================================
|
|
429
|
+
// HyperMind Agentic Framework API
|
|
430
|
+
// ==============================================
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Model types for HyperMind agents
|
|
434
|
+
*/
|
|
435
|
+
export type HyperMindModel = 'claude-sonnet-4' | 'claude-opus-4' | 'gpt-4o' | 'gpt-4' | 'mock'
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Tool types available to HyperMind agents
|
|
439
|
+
*/
|
|
440
|
+
export type HyperMindTool =
|
|
441
|
+
| 'kg.sparql.query'
|
|
442
|
+
| 'kg.sparql.update'
|
|
443
|
+
| 'kg.motif.find'
|
|
444
|
+
| 'kg.datalog.apply'
|
|
445
|
+
| 'kg.semantic.search'
|
|
446
|
+
| 'kg.traversal.oneHop'
|
|
447
|
+
| 'kg.traversal.paths'
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Agent specification for spawning HyperMind agents
|
|
451
|
+
*/
|
|
452
|
+
export interface HyperMindAgentSpec {
|
|
453
|
+
/** Agent name for identification */
|
|
454
|
+
name: string
|
|
455
|
+
/** LLM model to use for neural planning */
|
|
456
|
+
model: HyperMindModel
|
|
457
|
+
/** Tools available to the agent */
|
|
458
|
+
tools: HyperMindTool[]
|
|
459
|
+
/** K8s cluster endpoint for rust-kgdb */
|
|
460
|
+
endpoint?: string
|
|
461
|
+
/** Maximum execution time in milliseconds */
|
|
462
|
+
timeout?: number
|
|
463
|
+
/** Enable detailed tracing */
|
|
464
|
+
tracing?: boolean
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Result of a HyperMind agent benchmark test
|
|
469
|
+
*/
|
|
470
|
+
export interface BenchmarkResult {
|
|
471
|
+
/** Test case question */
|
|
472
|
+
question: string
|
|
473
|
+
/** Whether syntax validation passed */
|
|
474
|
+
syntaxSuccess: boolean
|
|
475
|
+
/** Whether execution succeeded */
|
|
476
|
+
executionSuccess: boolean
|
|
477
|
+
/** Generated SPARQL query (if any) */
|
|
478
|
+
sparql?: string
|
|
479
|
+
/** Type errors caught by the framework */
|
|
480
|
+
typeErrorsCaught: number
|
|
481
|
+
/** Execution latency in milliseconds */
|
|
482
|
+
latencyMs: number
|
|
483
|
+
/** Error message if failed */
|
|
484
|
+
error?: string
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Aggregate benchmark statistics
|
|
489
|
+
*/
|
|
490
|
+
export interface BenchmarkStats {
|
|
491
|
+
/** Total test cases */
|
|
492
|
+
totalTests: number
|
|
493
|
+
/** Tests with valid syntax */
|
|
494
|
+
syntaxSuccess: number
|
|
495
|
+
/** Tests that executed successfully */
|
|
496
|
+
executionSuccess: number
|
|
497
|
+
/** Type errors caught before execution */
|
|
498
|
+
typeErrorsCaught: number
|
|
499
|
+
/** Average latency in milliseconds */
|
|
500
|
+
avgLatencyMs: number
|
|
501
|
+
/** Raw results (successful rate without framework) */
|
|
502
|
+
rawSyntaxRate: number
|
|
503
|
+
/** HyperMind results (successful rate with framework) */
|
|
504
|
+
hypermindSyntaxRate: number
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Tool description for the type registry
|
|
509
|
+
*/
|
|
510
|
+
export interface ToolDescription {
|
|
511
|
+
/** Unique tool identifier */
|
|
512
|
+
id: string
|
|
513
|
+
/** Human-readable description */
|
|
514
|
+
description: string
|
|
515
|
+
/** Input type identifier */
|
|
516
|
+
inputType: string
|
|
517
|
+
/** Output type identifier */
|
|
518
|
+
outputType: string
|
|
519
|
+
/** Preconditions (optional) */
|
|
520
|
+
preconditions?: string[]
|
|
521
|
+
/** Postconditions (optional) */
|
|
522
|
+
postconditions?: string[]
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Planning context with available tools
|
|
527
|
+
*/
|
|
528
|
+
export interface PlanningContext {
|
|
529
|
+
/** Available tools */
|
|
530
|
+
tools: ToolDescription[]
|
|
531
|
+
/** Semantic hints for the planner */
|
|
532
|
+
hints: string[]
|
|
533
|
+
/** Database endpoint */
|
|
534
|
+
endpoint: string
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Execution trace entry for provenance
|
|
539
|
+
*/
|
|
540
|
+
export interface TraceEntry {
|
|
541
|
+
/** Timestamp */
|
|
542
|
+
timestamp: string
|
|
543
|
+
/** Tool that was executed */
|
|
544
|
+
tool: string
|
|
545
|
+
/** Input provided */
|
|
546
|
+
input: string
|
|
547
|
+
/** Output produced */
|
|
548
|
+
output: string
|
|
549
|
+
/** Duration in milliseconds */
|
|
550
|
+
durationMs: number
|
|
551
|
+
/** Success status */
|
|
552
|
+
success: boolean
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* HyperMind Agent - Neuro-Symbolic AI Agent
|
|
557
|
+
*
|
|
558
|
+
* Combines neural planning (LLMs) with symbolic execution (SPARQL/Datalog)
|
|
559
|
+
* for type-safe, auditable, enterprise-grade AI agents.
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* ```typescript
|
|
563
|
+
* // Spawn an agent targeting K8s cluster
|
|
564
|
+
* const agent = await HyperMindAgent.spawn({
|
|
565
|
+
* name: 'fraud-detector',
|
|
566
|
+
* model: 'claude-sonnet-4',
|
|
567
|
+
* tools: ['kg.sparql.query', 'kg.motif.find'],
|
|
568
|
+
* endpoint: 'http://rust-kgdb-coordinator:30080'
|
|
569
|
+
* })
|
|
570
|
+
*
|
|
571
|
+
* // Execute with natural language
|
|
572
|
+
* const result = await agent.call('Find all professors in the university database')
|
|
573
|
+
* console.log(result.sparql) // Generated SPARQL query
|
|
574
|
+
* console.log(result.results) // Query results
|
|
575
|
+
*
|
|
576
|
+
* // Get execution trace for audit
|
|
577
|
+
* const trace = agent.getTrace()
|
|
578
|
+
* ```
|
|
579
|
+
*/
|
|
580
|
+
export class HyperMindAgent {
|
|
581
|
+
/**
|
|
582
|
+
* Spawn a new HyperMind agent with the given specification
|
|
583
|
+
* @param spec - Agent specification
|
|
584
|
+
* @returns Promise resolving to the spawned agent
|
|
585
|
+
*/
|
|
586
|
+
static spawn(spec: HyperMindAgentSpec): Promise<HyperMindAgent>
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Execute a natural language request
|
|
590
|
+
* @param prompt - Natural language prompt
|
|
591
|
+
* @returns Promise with execution result
|
|
592
|
+
*/
|
|
593
|
+
call(prompt: string): Promise<{
|
|
594
|
+
sparql?: string
|
|
595
|
+
results: QueryResult[]
|
|
596
|
+
success: boolean
|
|
597
|
+
error?: string
|
|
598
|
+
}>
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Get the execution trace for this agent
|
|
602
|
+
* @returns Array of trace entries
|
|
603
|
+
*/
|
|
604
|
+
getTrace(): TraceEntry[]
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Get the planning context used by this agent
|
|
608
|
+
* @returns Planning context with tools and hints
|
|
609
|
+
*/
|
|
610
|
+
getContext(): PlanningContext
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Check if the agent is connected to the K8s cluster
|
|
614
|
+
* @returns True if connected
|
|
615
|
+
*/
|
|
616
|
+
isConnected(): Promise<boolean>
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Get agent name
|
|
620
|
+
*/
|
|
621
|
+
getName(): string
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Get agent model
|
|
625
|
+
*/
|
|
626
|
+
getModel(): HyperMindModel
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Retriever configuration for BrowseComp-Plus style benchmarks
|
|
631
|
+
*/
|
|
632
|
+
export interface RetrieverConfig {
|
|
633
|
+
/** Retriever type (e.g., 'mixedbread', 'voyage', 'openai') */
|
|
634
|
+
type: 'mixedbread' | 'voyage' | 'openai' | 'cohere'
|
|
635
|
+
/** Model identifier */
|
|
636
|
+
model?: string
|
|
637
|
+
/** Top-k documents to retrieve */
|
|
638
|
+
topK?: number
|
|
639
|
+
/** Reranking enabled */
|
|
640
|
+
rerank?: boolean
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* BrowseComp-Plus benchmark configuration
|
|
645
|
+
*
|
|
646
|
+
* Inspired by Anthropic's BrowseComp benchmark methodology:
|
|
647
|
+
* - Tests agent capability on complex, multi-step knowledge retrieval
|
|
648
|
+
* - Measures accuracy with and without framework assistance
|
|
649
|
+
* - Uses standardized retriever (Mixedbread) for fair comparison
|
|
650
|
+
*/
|
|
651
|
+
export interface BrowseCompPlusConfig {
|
|
652
|
+
/** Retriever configuration */
|
|
653
|
+
retriever: RetrieverConfig
|
|
654
|
+
/** Knowledge graph endpoint */
|
|
655
|
+
kgEndpoint: string
|
|
656
|
+
/** Enable document access */
|
|
657
|
+
documentAccess: boolean
|
|
658
|
+
/** Maximum tool calls per query */
|
|
659
|
+
maxToolCalls?: number
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Run HyperMind benchmark comparing raw LLM vs LLM + HyperMind framework
|
|
664
|
+
*
|
|
665
|
+
* **BrowseComp-Plus Style Benchmark**:
|
|
666
|
+
* Given the same tools (access to a Mixedbread retriever and document access),
|
|
667
|
+
* measures LLM performance with and without HyperMind's typed tool composition.
|
|
668
|
+
*
|
|
669
|
+
* Tests 12 LUBM (Lehigh University Benchmark) natural language to SPARQL queries:
|
|
670
|
+
* - Easy (3): Simple pattern matching
|
|
671
|
+
* - Medium (5): Joins and aggregations
|
|
672
|
+
* - Hard (4): Complex multi-hop queries
|
|
673
|
+
*
|
|
674
|
+
* @param endpoint - K8s rust-kgdb endpoint (e.g., 'http://rust-kgdb-coordinator:30080')
|
|
675
|
+
* @param model - LLM model to benchmark
|
|
676
|
+
* @param options - Optional configuration
|
|
677
|
+
* @returns Promise with benchmark statistics
|
|
678
|
+
*
|
|
679
|
+
* @example
|
|
680
|
+
* ```typescript
|
|
681
|
+
* // Run BrowseComp-Plus style benchmark against K8s cluster
|
|
682
|
+
* const stats = await runHyperMindBenchmark(
|
|
683
|
+
* 'http://rust-kgdb-coordinator:30080',
|
|
684
|
+
* 'claude-sonnet-4',
|
|
685
|
+
* {
|
|
686
|
+
* saveResults: true,
|
|
687
|
+
* browseCompPlus: {
|
|
688
|
+
* retriever: { type: 'mixedbread', topK: 10 },
|
|
689
|
+
* kgEndpoint: 'http://rust-kgdb-coordinator:30080',
|
|
690
|
+
* documentAccess: true
|
|
691
|
+
* }
|
|
692
|
+
* }
|
|
693
|
+
* )
|
|
694
|
+
*
|
|
695
|
+
* // Results show: GPT-5 scored 77.11% with HyperMind vs 73.25% without
|
|
696
|
+
* console.log(`Raw accuracy: ${stats.rawSyntaxRate}%`)
|
|
697
|
+
* console.log(`HyperMind accuracy: ${stats.hypermindSyntaxRate}%`)
|
|
698
|
+
* console.log(`Improvement: +${(stats.hypermindSyntaxRate - stats.rawSyntaxRate).toFixed(2)}%`)
|
|
699
|
+
* ```
|
|
700
|
+
*/
|
|
701
|
+
export function runHyperMindBenchmark(
|
|
702
|
+
endpoint: string,
|
|
703
|
+
model: HyperMindModel,
|
|
704
|
+
options?: {
|
|
705
|
+
/** Save results to file */
|
|
706
|
+
saveResults?: boolean
|
|
707
|
+
/** Test timeout in milliseconds */
|
|
708
|
+
timeout?: number
|
|
709
|
+
/** Run only specific test indices */
|
|
710
|
+
testIndices?: number[]
|
|
711
|
+
/** BrowseComp-Plus style benchmark configuration */
|
|
712
|
+
browseCompPlus?: BrowseCompPlusConfig
|
|
713
|
+
}
|
|
714
|
+
): Promise<BenchmarkStats>
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* Get the LUBM benchmark test suite
|
|
718
|
+
* @returns Array of test case descriptions
|
|
719
|
+
*/
|
|
720
|
+
export function getHyperMindBenchmarkSuite(): Array<{
|
|
721
|
+
index: number
|
|
722
|
+
question: string
|
|
723
|
+
difficulty: 'easy' | 'medium' | 'hard'
|
|
724
|
+
expectedPattern: string
|
|
725
|
+
}>
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Validate SPARQL syntax without execution
|
|
729
|
+
* @param sparql - SPARQL query string
|
|
730
|
+
* @returns True if syntax is valid
|
|
731
|
+
*/
|
|
732
|
+
export function validateSparqlSyntax(sparql: string): boolean
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Create a planning context with typed tool definitions
|
|
736
|
+
* @param endpoint - K8s endpoint
|
|
737
|
+
* @param hints - Semantic hints for the planner
|
|
738
|
+
* @returns Planning context
|
|
739
|
+
*/
|
|
740
|
+
export function createPlanningContext(
|
|
741
|
+
endpoint: string,
|
|
742
|
+
hints?: string[]
|
|
743
|
+
): PlanningContext
|
package/index.js
CHANGED
|
@@ -54,6 +54,15 @@ const {
|
|
|
54
54
|
pregelShortestPaths,
|
|
55
55
|
} = loadNativeBinding()
|
|
56
56
|
|
|
57
|
+
// HyperMind Agentic Framework
|
|
58
|
+
const {
|
|
59
|
+
HyperMindAgent,
|
|
60
|
+
runHyperMindBenchmark,
|
|
61
|
+
getHyperMindBenchmarkSuite,
|
|
62
|
+
validateSparqlSyntax,
|
|
63
|
+
createPlanningContext,
|
|
64
|
+
} = require('./hypermind-agent')
|
|
65
|
+
|
|
57
66
|
module.exports = {
|
|
58
67
|
// Core GraphDB
|
|
59
68
|
GraphDB: GraphDb, // Export as GraphDB for consistency
|
|
@@ -76,4 +85,10 @@ module.exports = {
|
|
|
76
85
|
queryDatalog,
|
|
77
86
|
// Pregel API - Bulk Synchronous Parallel Processing
|
|
78
87
|
pregelShortestPaths,
|
|
88
|
+
// HyperMind Agentic Framework API
|
|
89
|
+
HyperMindAgent,
|
|
90
|
+
runHyperMindBenchmark,
|
|
91
|
+
getHyperMindBenchmarkSuite,
|
|
92
|
+
validateSparqlSyntax,
|
|
93
|
+
createPlanningContext,
|
|
79
94
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rust-kgdb",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "High-performance RDF/SPARQL database with GraphFrames analytics, vector embeddings, Datalog reasoning, Pregel BSP processing, and HyperMind neuro-symbolic agentic framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|