rust-kgdb 0.3.9 → 0.3.11
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 +164 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -574,6 +574,30 @@ console.log('Bipartite(3,4):', bp34.vertexCount(), 'vertices,', bp34.edgeCount()
|
|
|
574
574
|
|
|
575
575
|
## 7. HyperMind Agentic Framework (Neuro-Symbolic AI)
|
|
576
576
|
|
|
577
|
+
### ⚡ TL;DR: What is HyperMind?
|
|
578
|
+
|
|
579
|
+
**HyperMind converts natural language questions into SPARQL queries.**
|
|
580
|
+
|
|
581
|
+
```typescript
|
|
582
|
+
// Input: "Find all professors"
|
|
583
|
+
// Output: "SELECT ?x WHERE { ?x a ub:Professor }"
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
**NOT to be confused with:**
|
|
587
|
+
- ❌ **EmbeddingService** - That's for semantic similarity search (different feature)
|
|
588
|
+
- ❌ **GraphDB** - That's for direct SPARQL queries (no natural language)
|
|
589
|
+
|
|
590
|
+
### Quick Start: Create an Agent in 3 Lines
|
|
591
|
+
|
|
592
|
+
```typescript
|
|
593
|
+
const { HyperMindAgent } = require('rust-kgdb')
|
|
594
|
+
|
|
595
|
+
const agent = await HyperMindAgent.spawn({ model: 'mock', endpoint: 'http://localhost:30080' })
|
|
596
|
+
const result = await agent.call('Find all professors') // → SPARQL query + results
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
---
|
|
600
|
+
|
|
577
601
|
HyperMind is a **production-grade neuro-symbolic agentic framework** built on rust-kgdb that combines:
|
|
578
602
|
|
|
579
603
|
- **Type Theory**: Compile-time safety with typed tool contracts
|
|
@@ -581,42 +605,167 @@ HyperMind is a **production-grade neuro-symbolic agentic framework** built on ru
|
|
|
581
605
|
- **Neural Planning**: LLM-based planning (Claude, GPT-4o)
|
|
582
606
|
- **Symbolic Execution**: rust-kgdb knowledge graph operations
|
|
583
607
|
|
|
584
|
-
###
|
|
608
|
+
### How It Works: Two Modes
|
|
609
|
+
|
|
610
|
+
```
|
|
611
|
+
┌─────────────────────────────────────────────────────────────────────────────┐
|
|
612
|
+
│ HyperMind Agent Flow │
|
|
613
|
+
├─────────────────────────────────────────────────────────────────────────────┤
|
|
614
|
+
│ │
|
|
615
|
+
│ User: "Find all professors" │
|
|
616
|
+
│ │ │
|
|
617
|
+
│ ▼ │
|
|
618
|
+
│ ┌─────────────────────────────────────────────────────────────────────┐ │
|
|
619
|
+
│ │ MODE 1: Mock (No API Keys) MODE 2: LLM (With API Keys) │ │
|
|
620
|
+
│ │ ───────────────────────────── ─────────────────────────── │ │
|
|
621
|
+
│ │ • Pattern matches question • Sends to Claude/GPT-4o │ │
|
|
622
|
+
│ │ • Returns pre-defined SPARQL • LLM generates SPARQL │ │
|
|
623
|
+
│ │ • Instant (~6ms latency) • ~2-6 second latency │ │
|
|
624
|
+
│ │ • For testing/benchmarks • For production use │ │
|
|
625
|
+
│ └─────────────────────────────────────────────────────────────────────┘ │
|
|
626
|
+
│ │ │
|
|
627
|
+
│ ▼ │
|
|
628
|
+
│ SPARQL Query: "SELECT ?x WHERE { ?x a ub:Professor }" │
|
|
629
|
+
│ │ │
|
|
630
|
+
│ ▼ │
|
|
631
|
+
│ rust-kgdb Cluster: Executes query, returns results │
|
|
632
|
+
│ │ │
|
|
633
|
+
│ ▼ │
|
|
634
|
+
│ Results: [{ bindings: { x: "http://..." } }, ...] │
|
|
635
|
+
│ │
|
|
636
|
+
└─────────────────────────────────────────────────────────────────────────────┘
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
### Mode 1: Mock Mode (No API Keys Required)
|
|
640
|
+
|
|
641
|
+
Use this for **testing, benchmarking, and development**. The mock model pattern-matches your question against 12 pre-defined LUBM queries:
|
|
585
642
|
|
|
586
643
|
```typescript
|
|
587
644
|
const { HyperMindAgent } = require('rust-kgdb')
|
|
588
645
|
|
|
589
|
-
//
|
|
646
|
+
// Spawn agent with mock model - NO API KEYS NEEDED
|
|
590
647
|
const agent = await HyperMindAgent.spawn({
|
|
591
|
-
name: '
|
|
592
|
-
model: 'mock', //
|
|
593
|
-
tools: ['kg.sparql.query'],
|
|
594
|
-
endpoint: 'http://localhost:30080' // rust-kgdb
|
|
648
|
+
name: 'test-agent',
|
|
649
|
+
model: 'mock', // Uses pattern matching, not LLM
|
|
650
|
+
tools: ['kg.sparql.query'],
|
|
651
|
+
endpoint: 'http://localhost:30080' // Your rust-kgdb endpoint
|
|
595
652
|
})
|
|
596
653
|
|
|
597
|
-
//
|
|
654
|
+
// Ask a question (pattern-matched to LUBM queries)
|
|
598
655
|
const result = await agent.call('Find all professors in the database')
|
|
599
656
|
|
|
600
|
-
// 3. Get results
|
|
601
|
-
console.log(result.sparql) // "PREFIX ub: <...> SELECT ?x WHERE { ?x a ub:Professor }"
|
|
602
|
-
console.log(result.results) // [{ bindings: { x: 'http://...' } }, ...]
|
|
603
657
|
console.log(result.success) // true
|
|
658
|
+
console.log(result.sparql) // "PREFIX ub: <...> SELECT ?x WHERE { ?x a ub:Professor }"
|
|
659
|
+
console.log(result.results) // Query results from your database
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
**Supported Mock Questions (12 LUBM patterns):**
|
|
663
|
+
| Question Pattern | Generated SPARQL |
|
|
664
|
+
|-----------------|------------------|
|
|
665
|
+
| "Find all professors..." | `SELECT ?x WHERE { ?x a ub:Professor }` |
|
|
666
|
+
| "List all graduate students" | `SELECT ?x WHERE { ?x a ub:GraduateStudent }` |
|
|
667
|
+
| "How many courses..." | `SELECT (COUNT(?x) AS ?count) WHERE { ?x a ub:Course }` |
|
|
668
|
+
| "Find students and their advisors" | `SELECT ?student ?advisor WHERE { ?student ub:advisor ?advisor }` |
|
|
669
|
+
|
|
670
|
+
### Mode 2: LLM Mode (Requires API Keys)
|
|
671
|
+
|
|
672
|
+
Use this for **production** with real LLM-powered query generation:
|
|
673
|
+
|
|
674
|
+
```bash
|
|
675
|
+
# Set environment variables BEFORE running your code
|
|
676
|
+
export ANTHROPIC_API_KEY="sk-ant-api03-..." # For Claude
|
|
677
|
+
export OPENAI_API_KEY="sk-proj-..." # For GPT-4o
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
```typescript
|
|
681
|
+
const { HyperMindAgent } = require('rust-kgdb')
|
|
682
|
+
|
|
683
|
+
// Spawn agent with Claude (requires ANTHROPIC_API_KEY)
|
|
684
|
+
const agent = await HyperMindAgent.spawn({
|
|
685
|
+
name: 'prod-agent',
|
|
686
|
+
model: 'claude-sonnet-4', // Real LLM - generates dynamic SPARQL
|
|
687
|
+
tools: ['kg.sparql.query', 'kg.motif.find'],
|
|
688
|
+
endpoint: 'http://localhost:30080'
|
|
689
|
+
})
|
|
690
|
+
|
|
691
|
+
// Any natural language question works (not limited to patterns)
|
|
692
|
+
const result = await agent.call('Find professors who teach AI and have more than 5 publications')
|
|
693
|
+
|
|
694
|
+
// LLM generates appropriate SPARQL dynamically
|
|
695
|
+
console.log(result.sparql) // Complex query generated by Claude
|
|
604
696
|
```
|
|
605
697
|
|
|
606
|
-
|
|
698
|
+
**Supported LLM Models:**
|
|
699
|
+
| Model | Environment Variable | Use Case |
|
|
700
|
+
|-------|---------------------|----------|
|
|
701
|
+
| `claude-sonnet-4` | `ANTHROPIC_API_KEY` | Best accuracy |
|
|
702
|
+
| `gpt-4o` | `OPENAI_API_KEY` | Alternative |
|
|
703
|
+
| `mock` | None | Testing only |
|
|
704
|
+
|
|
705
|
+
### Run the Benchmark
|
|
607
706
|
|
|
608
707
|
```typescript
|
|
609
708
|
const { runHyperMindBenchmark } = require('rust-kgdb')
|
|
610
709
|
|
|
611
|
-
//
|
|
710
|
+
// Test with mock model (no API keys)
|
|
612
711
|
const stats = await runHyperMindBenchmark('http://localhost:30080', 'mock', {
|
|
613
|
-
saveResults: true // Saves
|
|
712
|
+
saveResults: true // Saves JSON file with results
|
|
614
713
|
})
|
|
615
714
|
|
|
616
|
-
console.log(`Success
|
|
617
|
-
console.log(`
|
|
715
|
+
console.log(`Success: ${stats.syntaxSuccess}/${stats.totalTests}`) // 12/12
|
|
716
|
+
console.log(`Latency: ${stats.avgLatencyMs.toFixed(1)}ms`) // ~6.58ms
|
|
618
717
|
```
|
|
619
718
|
|
|
719
|
+
### ⚠️ Important: Embeddings Are SEPARATE from HyperMind
|
|
720
|
+
|
|
721
|
+
```
|
|
722
|
+
┌───────────────────────────────────────────────────────────────────────────────┐
|
|
723
|
+
│ COMMON CONFUSION: These are TWO DIFFERENT FEATURES │
|
|
724
|
+
├───────────────────────────────────────────────────────────────────────────────┤
|
|
725
|
+
│ │
|
|
726
|
+
│ HyperMindAgent EmbeddingService │
|
|
727
|
+
│ ───────────────── ───────────────── │
|
|
728
|
+
│ • Natural Language → SPARQL • Text → Vector embeddings │
|
|
729
|
+
│ • "Find professors" → SQL-like query • "professor" → [0.1, 0.2, ...] │
|
|
730
|
+
│ • Returns database results • Returns similar items │
|
|
731
|
+
│ • NO embeddings used internally • ALL about embeddings │
|
|
732
|
+
│ │
|
|
733
|
+
│ Use HyperMind when: Use Embeddings when: │
|
|
734
|
+
│ "I want to query my database "I want to find semantically │
|
|
735
|
+
│ using natural language" similar items" │
|
|
736
|
+
│ │
|
|
737
|
+
└───────────────────────────────────────────────────────────────────────────────┘
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
```typescript
|
|
741
|
+
const { HyperMindAgent, EmbeddingService, GraphDB } = require('rust-kgdb')
|
|
742
|
+
|
|
743
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
744
|
+
// HYPERMIND: Natural language → SPARQL queries (NO embeddings)
|
|
745
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
746
|
+
const agent = await HyperMindAgent.spawn({ model: 'mock', endpoint: 'http://localhost:30080' })
|
|
747
|
+
const result = await agent.call('Find all professors')
|
|
748
|
+
// result.sparql = "SELECT ?x WHERE { ?x a ub:Professor }"
|
|
749
|
+
// result.results = [{ x: "http://university.edu/prof1" }, ...]
|
|
750
|
+
|
|
751
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
752
|
+
// EMBEDDINGS: Semantic similarity search (COMPLETELY SEPARATE)
|
|
753
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
754
|
+
const embeddings = new EmbeddingService()
|
|
755
|
+
embeddings.storeVector('professor', [0.1, 0.2, 0.3, ...]) // 384-dim vector
|
|
756
|
+
embeddings.storeVector('teacher', [0.11, 0.21, 0.31, ...])
|
|
757
|
+
const similar = embeddings.findSimilar('professor', 5) // Finds "teacher" by cosine similarity
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
| Feature | HyperMindAgent | EmbeddingService |
|
|
761
|
+
|---------|----------------|------------------|
|
|
762
|
+
| **What it does** | NL → SPARQL queries | Semantic similarity search |
|
|
763
|
+
| **Input** | "Find all professors" | Text or vectors |
|
|
764
|
+
| **Output** | SPARQL query + results | Similar items list |
|
|
765
|
+
| **Uses embeddings?** | ❌ **NO** | ✅ Yes |
|
|
766
|
+
| **Uses LLM?** | ✅ Yes (or mock) | ❌ No |
|
|
767
|
+
| **Requires API key?** | Only for LLM mode | No |
|
|
768
|
+
|
|
620
769
|
### Architecture Overview
|
|
621
770
|
|
|
622
771
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rust-kgdb",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.11",
|
|
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",
|