rust-kgdb 0.3.4 → 0.3.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 +308 -0
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -572,6 +572,314 @@ console.log('Bipartite(3,4):', bp34.vertexCount(), 'vertices,', bp34.edgeCount()
|
|
|
572
572
|
|
|
573
573
|
---
|
|
574
574
|
|
|
575
|
+
## 7. HyperMind Agentic Framework (Neuro-Symbolic AI)
|
|
576
|
+
|
|
577
|
+
HyperMind is a **production-grade neuro-symbolic agentic framework** built on rust-kgdb that combines:
|
|
578
|
+
|
|
579
|
+
- **Type Theory**: Compile-time safety with typed tool contracts
|
|
580
|
+
- **Category Theory**: Tools as morphisms with composable guarantees
|
|
581
|
+
- **Neural Planning**: LLM-based planning (Claude, GPT-4o)
|
|
582
|
+
- **Symbolic Execution**: rust-kgdb knowledge graph operations
|
|
583
|
+
|
|
584
|
+
### Architecture Overview
|
|
585
|
+
|
|
586
|
+
```
|
|
587
|
+
┌─────────────────────────────────────────────────────────────────────────────┐
|
|
588
|
+
│ HyperMind Architecture │
|
|
589
|
+
├─────────────────────────────────────────────────────────────────────────────┤
|
|
590
|
+
│ │
|
|
591
|
+
│ Layer 5: Agent SDKs (TypeScript / Python / Kotlin) │
|
|
592
|
+
│ spawn(), agentic() functions, type-safe agent definitions │
|
|
593
|
+
│ │
|
|
594
|
+
│ Layer 4: Agent Runtime (Rust) │
|
|
595
|
+
│ Planner trait, Plan executor, Type checking, Reflection │
|
|
596
|
+
│ │
|
|
597
|
+
│ Layer 3: Typed Tool Wrappers │
|
|
598
|
+
│ SparqlMorphism, MotifMorphism, DatalogMorphism │
|
|
599
|
+
│ │
|
|
600
|
+
│ Layer 2: Category Theory Foundation │
|
|
601
|
+
│ Morphism trait, Composition, Functor, Monad │
|
|
602
|
+
│ │
|
|
603
|
+
│ Layer 1: Type System Foundation │
|
|
604
|
+
│ TypeId, Constraints, Type Registry │
|
|
605
|
+
│ │
|
|
606
|
+
│ Layer 0: rust-kgdb Engine (UNCHANGED) │
|
|
607
|
+
│ storage, sparql, cluster (this SDK) │
|
|
608
|
+
│ │
|
|
609
|
+
└─────────────────────────────────────────────────────────────────────────────┘
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
### Core Concepts
|
|
613
|
+
|
|
614
|
+
#### TypeId - Type System Foundation
|
|
615
|
+
|
|
616
|
+
```typescript
|
|
617
|
+
// TypeId enum defines all types in the system
|
|
618
|
+
enum TypeId {
|
|
619
|
+
Unit, // ()
|
|
620
|
+
Bool, // boolean
|
|
621
|
+
Int64, // 64-bit integer
|
|
622
|
+
Float64, // 64-bit float
|
|
623
|
+
String, // UTF-8 string
|
|
624
|
+
Node, // RDF Node
|
|
625
|
+
Triple, // RDF Triple
|
|
626
|
+
Quad, // RDF Quad
|
|
627
|
+
BindingSet, // SPARQL solution set
|
|
628
|
+
Record, // Named fields: Record<{name: String, age: Int64}>
|
|
629
|
+
List, // Homogeneous list: List<Node>
|
|
630
|
+
Option, // Optional value: Option<String>
|
|
631
|
+
Function, // Function type: A → B
|
|
632
|
+
}
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
#### Morphism - Category Theory Abstraction
|
|
636
|
+
|
|
637
|
+
A **Morphism** is a typed function between objects with composable guarantees:
|
|
638
|
+
|
|
639
|
+
```typescript
|
|
640
|
+
// Morphism trait - a typed function between objects
|
|
641
|
+
interface Morphism<Input, Output> {
|
|
642
|
+
apply(input: Input): Result<Output, MorphismError>
|
|
643
|
+
inputType(): TypeId
|
|
644
|
+
outputType(): TypeId
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// Example: SPARQL query as a morphism
|
|
648
|
+
// SparqlMorphism: String → BindingSet
|
|
649
|
+
const sparqlQuery: Morphism<string, BindingSet> = {
|
|
650
|
+
inputType: () => TypeId.String,
|
|
651
|
+
outputType: () => TypeId.BindingSet,
|
|
652
|
+
apply: (query) => db.querySelect(query)
|
|
653
|
+
}
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
#### ToolDescription - Typed Tool Contracts
|
|
657
|
+
|
|
658
|
+
```typescript
|
|
659
|
+
interface ToolDescription {
|
|
660
|
+
name: string // "kg.sparql.query"
|
|
661
|
+
description: string // "Execute SPARQL queries"
|
|
662
|
+
inputType: TypeId // TypeId.String
|
|
663
|
+
outputType: TypeId // TypeId.BindingSet
|
|
664
|
+
examples: string[] // Example queries
|
|
665
|
+
capabilities: string[] // ["query", "filter", "aggregate"]
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// Available HyperMind tools
|
|
669
|
+
const tools: ToolDescription[] = [
|
|
670
|
+
{ name: "kg.sparql.query", input: TypeId.String, output: TypeId.BindingSet },
|
|
671
|
+
{ name: "kg.motif.find", input: TypeId.String, output: TypeId.BindingSet },
|
|
672
|
+
{ name: "kg.datalog.apply", input: TypeId.String, output: TypeId.BindingSet },
|
|
673
|
+
{ name: "kg.semantic.search", input: TypeId.String, output: TypeId.List },
|
|
674
|
+
{ name: "kg.traverse.neighbors", input: TypeId.Node, output: TypeId.List },
|
|
675
|
+
]
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
#### PlanningContext - Scope for Neural Planning
|
|
679
|
+
|
|
680
|
+
```typescript
|
|
681
|
+
interface PlanningContext {
|
|
682
|
+
tools: ToolDescription[] // Available tools
|
|
683
|
+
scopeBindings: Map<string, string> // Variables in scope
|
|
684
|
+
feedback: string | null // Error feedback from previous attempt
|
|
685
|
+
hints: string[] // Domain hints for the LLM
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// Create planning context
|
|
689
|
+
const context: PlanningContext = {
|
|
690
|
+
tools: [sparqlTool, motifTool],
|
|
691
|
+
scopeBindings: new Map([["dataset", "lubm"]]),
|
|
692
|
+
feedback: null,
|
|
693
|
+
hints: [
|
|
694
|
+
"Database uses LUBM ontology",
|
|
695
|
+
"Key classes: Professor, GraduateStudent, Course"
|
|
696
|
+
]
|
|
697
|
+
}
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
#### Planner - Neural Planning Interface
|
|
701
|
+
|
|
702
|
+
```typescript
|
|
703
|
+
interface Planner {
|
|
704
|
+
plan(prompt: string, context: PlanningContext): Promise<Plan>
|
|
705
|
+
name(): string
|
|
706
|
+
config(): PlannerConfig
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// Supported planners
|
|
710
|
+
type PlannerType =
|
|
711
|
+
| { type: "claude", model: "claude-sonnet-4" }
|
|
712
|
+
| { type: "openai", model: "gpt-4o" }
|
|
713
|
+
| { type: "local", model: "ollama/mistral" }
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
### Neuro-Symbolic Planning Loop
|
|
717
|
+
|
|
718
|
+
```
|
|
719
|
+
┌─────────────────────────────────────────────────────────────────────────────┐
|
|
720
|
+
│ NEURO-SYMBOLIC PLANNING │
|
|
721
|
+
├─────────────────────────────────────────────────────────────────────────────┤
|
|
722
|
+
│ │
|
|
723
|
+
│ User Prompt: "Find professors in the AI department" │
|
|
724
|
+
│ │ │
|
|
725
|
+
│ ▼ │
|
|
726
|
+
│ ┌─────────────────┐ │
|
|
727
|
+
│ │ Neural Planner │ (Claude Sonnet 4 / GPT-4o) │
|
|
728
|
+
│ │ - Understands intent │
|
|
729
|
+
│ │ - Discovers available tools │
|
|
730
|
+
│ │ - Generates tool sequence │
|
|
731
|
+
│ └────────┬────────┘ │
|
|
732
|
+
│ │ Plan: [kg.sparql.query] │
|
|
733
|
+
│ ▼ │
|
|
734
|
+
│ ┌─────────────────┐ │
|
|
735
|
+
│ │ Type Checker │ (Compile-time verification) │
|
|
736
|
+
│ │ - Validates composition │
|
|
737
|
+
│ │ - Checks pre/post conditions │
|
|
738
|
+
│ │ - Verifies type compatibility │
|
|
739
|
+
│ └────────┬────────┘ │
|
|
740
|
+
│ │ Validated Plan │
|
|
741
|
+
│ ▼ │
|
|
742
|
+
│ ┌─────────────────┐ │
|
|
743
|
+
│ │ Symbolic Executor│ (rust-kgdb) │
|
|
744
|
+
│ │ - Executes SPARQL │
|
|
745
|
+
│ │ - Returns typed results │
|
|
746
|
+
│ │ - Records trace │
|
|
747
|
+
│ └────────┬────────┘ │
|
|
748
|
+
│ │ Result or Error │
|
|
749
|
+
│ ▼ │
|
|
750
|
+
│ ┌─────────────────┐ │
|
|
751
|
+
│ │ Reflection │ │
|
|
752
|
+
│ │ - Success? Return result │
|
|
753
|
+
│ │ - Failure? Generate feedback │
|
|
754
|
+
│ │ - Loop back to planner with context │
|
|
755
|
+
│ └─────────────────┘ │
|
|
756
|
+
│ │
|
|
757
|
+
└─────────────────────────────────────────────────────────────────────────────┘
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
### TypeScript SDK Usage (Coming Soon)
|
|
761
|
+
|
|
762
|
+
```typescript
|
|
763
|
+
import { spawn, PlanningContext } from '@hypermind/sdk'
|
|
764
|
+
import { GraphDB } from 'rust-kgdb'
|
|
765
|
+
|
|
766
|
+
// 1. Create planning context with typed tools
|
|
767
|
+
const context = new PlanningContext([
|
|
768
|
+
{ name: 'kg.sparql.query', input: TypeId.String, output: TypeId.BindingSet }
|
|
769
|
+
])
|
|
770
|
+
.withHint('Database uses LUBM ontology')
|
|
771
|
+
.withHint('Key classes: Professor, GraduateStudent, Course')
|
|
772
|
+
|
|
773
|
+
// 2. Spawn an agent with tools and context
|
|
774
|
+
const agent = await spawn({
|
|
775
|
+
name: 'professor-finder',
|
|
776
|
+
model: 'claude-sonnet-4',
|
|
777
|
+
tools: ['kg.sparql.query', 'kg.motif.find']
|
|
778
|
+
}, {
|
|
779
|
+
kg: new GraphDB('http://localhost:30080'),
|
|
780
|
+
context
|
|
781
|
+
})
|
|
782
|
+
|
|
783
|
+
// 3. Execute with type-safe result
|
|
784
|
+
interface Professor {
|
|
785
|
+
uri: string
|
|
786
|
+
name: string
|
|
787
|
+
department: string
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
const professors = await agent.call<Professor[]>(
|
|
791
|
+
'Find professors who teach AI courses and advise graduate students'
|
|
792
|
+
)
|
|
793
|
+
|
|
794
|
+
// 4. Type-checked at compile time!
|
|
795
|
+
console.log(professors[0].name) // TypeScript knows this is a string
|
|
796
|
+
```
|
|
797
|
+
|
|
798
|
+
### Category Theory Composition
|
|
799
|
+
|
|
800
|
+
HyperMind enforces **type safety at planning time** using category theory:
|
|
801
|
+
|
|
802
|
+
```typescript
|
|
803
|
+
// Tools are morphisms with input/output types
|
|
804
|
+
const sparqlQuery: Morphism<string, BindingSet>
|
|
805
|
+
const extractNodes: Morphism<BindingSet, Node[]>
|
|
806
|
+
const findSimilar: Morphism<Node, Node[]>
|
|
807
|
+
|
|
808
|
+
// Composition is type-checked
|
|
809
|
+
const pipeline = compose(sparqlQuery, extractNodes, findSimilar)
|
|
810
|
+
// ✓ String → BindingSet → Node[] → Node[]
|
|
811
|
+
|
|
812
|
+
// TYPE ERROR: BindingSet cannot be input to findSimilar (requires Node)
|
|
813
|
+
const invalid = compose(sparqlQuery, findSimilar)
|
|
814
|
+
// ✗ Compile error: BindingSet is not assignable to Node
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
### Value Proposition
|
|
818
|
+
|
|
819
|
+
| Feature | HyperMind | LangChain | AutoGPT |
|
|
820
|
+
|---------|-----------|-----------|---------|
|
|
821
|
+
| **Type Safety** | ✅ Compile-time | ❌ Runtime | ❌ Runtime |
|
|
822
|
+
| **Category Theory** | ✅ Full (Morphism, Functor, Monad) | ❌ None | ❌ None |
|
|
823
|
+
| **KG Integration** | ✅ Native SPARQL/Datalog | ⚠️ Plugin | ⚠️ Plugin |
|
|
824
|
+
| **Provenance** | ✅ Full execution trace | ⚠️ Partial | ❌ None |
|
|
825
|
+
| **Tool Composition** | ✅ Verified at planning time | ❌ Runtime errors | ❌ Runtime errors |
|
|
826
|
+
|
|
827
|
+
### HyperMind Agentic Benchmark (Claude vs GPT-4o)
|
|
828
|
+
|
|
829
|
+
HyperMind was benchmarked using the **LUBM (Lehigh University Benchmark)** - the industry-standard benchmark for Semantic Web databases. LUBM provides a standardized ontology (universities, professors, students, courses) with 14 canonical queries of varying complexity.
|
|
830
|
+
|
|
831
|
+
**Benchmark Configuration:**
|
|
832
|
+
- **Dataset**: LUBM(1) - 3,272 triples (1 university)
|
|
833
|
+
- **Queries**: 12 LUBM queries (Q1-Q12)
|
|
834
|
+
- **LLM Models**: Claude Sonnet 4, GPT-4o
|
|
835
|
+
- **Test Protocol**: Raw LLM vs HyperMind framework comparison
|
|
836
|
+
|
|
837
|
+
| Metric | Claude Sonnet 4 | GPT-4o |
|
|
838
|
+
|--------|-----------------|--------|
|
|
839
|
+
| **Syntax Success (Raw LLM)** | 0% (0/12) | 100% (12/12) |
|
|
840
|
+
| **Syntax Success (HyperMind)** | **92% (11/12)** | 75% (9/12) |
|
|
841
|
+
| **Type Errors Caught** | 1 | 3 |
|
|
842
|
+
| **Framework Overhead** | 6.2s avg | 3.0s avg |
|
|
843
|
+
|
|
844
|
+
**Key Findings:**
|
|
845
|
+
|
|
846
|
+
1. **HyperMind improves Claude's SPARQL generation from 0% to 92%** by forcing structured output (Claude raw responses include markdown formatting that fails SPARQL validation)
|
|
847
|
+
|
|
848
|
+
2. **HyperMind catches type errors before execution** - 3 type errors caught for GPT-4o queries that would have failed at runtime
|
|
849
|
+
|
|
850
|
+
3. **The 75% vs 100% for GPT-4o is a feature** - rejected queries had type mismatches that the type checker caught
|
|
851
|
+
|
|
852
|
+
**Why HyperMind Works:**
|
|
853
|
+
- **Structured Output**: Forces LLMs to return JSON with typed fields, not markdown-wrapped code
|
|
854
|
+
- **Type Checking**: Validates morphism composition (String → BindingSet → Node[]) at planning time
|
|
855
|
+
- **Reflection Loop**: Failed queries retry with error feedback in context
|
|
856
|
+
|
|
857
|
+
**LUBM Reference**: [Lehigh University Benchmark](http://swat.cse.lehigh.edu/projects/lubm/) - standardized by W3C for Semantic Web database evaluation
|
|
858
|
+
|
|
859
|
+
### SDK Benchmark Results
|
|
860
|
+
|
|
861
|
+
| Operation | Throughput | Latency |
|
|
862
|
+
|-----------|------------|---------|
|
|
863
|
+
| **Single Triple Insert** | 6,438 ops/sec | 155 μs |
|
|
864
|
+
| **Bulk Insert (1000 triples)** | 112 batches/sec | 8.96 ms |
|
|
865
|
+
| **Simple SELECT** | 1,137 queries/sec | 880 μs |
|
|
866
|
+
| **JOIN Query** | 295 queries/sec | 3.39 ms |
|
|
867
|
+
| **COUNT Aggregation** | 1,158 queries/sec | 863 μs |
|
|
868
|
+
|
|
869
|
+
Memory efficiency: **24 bytes/triple** in Rust native memory (zero-copy).
|
|
870
|
+
|
|
871
|
+
### Full Documentation
|
|
872
|
+
|
|
873
|
+
For complete HyperMind documentation including:
|
|
874
|
+
- Rust implementation details
|
|
875
|
+
- All crate structures (hypermind-types, hypermind-category, hypermind-tools, hypermind-runtime)
|
|
876
|
+
- Session types for multi-agent protocols
|
|
877
|
+
- Python SDK examples
|
|
878
|
+
|
|
879
|
+
See: [HyperMind Agentic Framework Documentation](https://github.com/gonnect-uk/rust-kgdb/blob/main/docs/HYPERMIND_AGENTIC_FRAMEWORK.md)
|
|
880
|
+
|
|
881
|
+
---
|
|
882
|
+
|
|
575
883
|
## Core RDF/SPARQL Database
|
|
576
884
|
|
|
577
885
|
> **This npm package provides the high-performance in-memory database.**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rust-kgdb",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "High-performance RDF/SPARQL database with GraphFrames analytics, vector embeddings, Datalog reasoning,
|
|
3
|
+
"version": "0.3.5",
|
|
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",
|
|
7
7
|
"napi": {
|
|
@@ -36,7 +36,15 @@
|
|
|
36
36
|
"datalog",
|
|
37
37
|
"pregel",
|
|
38
38
|
"napi-rs",
|
|
39
|
-
"rust"
|
|
39
|
+
"rust",
|
|
40
|
+
"hypermind",
|
|
41
|
+
"agentic",
|
|
42
|
+
"neuro-symbolic",
|
|
43
|
+
"category-theory",
|
|
44
|
+
"type-theory",
|
|
45
|
+
"llm",
|
|
46
|
+
"morphism",
|
|
47
|
+
"lubm-benchmark"
|
|
40
48
|
],
|
|
41
49
|
"author": "Gonnect Team",
|
|
42
50
|
"license": "Apache-2.0",
|