rust-kgdb 0.3.8 → 0.3.10
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 +137 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -581,6 +581,143 @@ HyperMind is a **production-grade neuro-symbolic agentic framework** built on ru
|
|
|
581
581
|
- **Neural Planning**: LLM-based planning (Claude, GPT-4o)
|
|
582
582
|
- **Symbolic Execution**: rust-kgdb knowledge graph operations
|
|
583
583
|
|
|
584
|
+
### How It Works: Two Modes
|
|
585
|
+
|
|
586
|
+
```
|
|
587
|
+
┌─────────────────────────────────────────────────────────────────────────────┐
|
|
588
|
+
│ HyperMind Agent Flow │
|
|
589
|
+
├─────────────────────────────────────────────────────────────────────────────┤
|
|
590
|
+
│ │
|
|
591
|
+
│ User: "Find all professors" │
|
|
592
|
+
│ │ │
|
|
593
|
+
│ ▼ │
|
|
594
|
+
│ ┌─────────────────────────────────────────────────────────────────────┐ │
|
|
595
|
+
│ │ MODE 1: Mock (No API Keys) MODE 2: LLM (With API Keys) │ │
|
|
596
|
+
│ │ ───────────────────────────── ─────────────────────────── │ │
|
|
597
|
+
│ │ • Pattern matches question • Sends to Claude/GPT-4o │ │
|
|
598
|
+
│ │ • Returns pre-defined SPARQL • LLM generates SPARQL │ │
|
|
599
|
+
│ │ • Instant (~6ms latency) • ~2-6 second latency │ │
|
|
600
|
+
│ │ • For testing/benchmarks • For production use │ │
|
|
601
|
+
│ └─────────────────────────────────────────────────────────────────────┘ │
|
|
602
|
+
│ │ │
|
|
603
|
+
│ ▼ │
|
|
604
|
+
│ SPARQL Query: "SELECT ?x WHERE { ?x a ub:Professor }" │
|
|
605
|
+
│ │ │
|
|
606
|
+
│ ▼ │
|
|
607
|
+
│ rust-kgdb Cluster: Executes query, returns results │
|
|
608
|
+
│ │ │
|
|
609
|
+
│ ▼ │
|
|
610
|
+
│ Results: [{ bindings: { x: "http://..." } }, ...] │
|
|
611
|
+
│ │
|
|
612
|
+
└─────────────────────────────────────────────────────────────────────────────┘
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
### Mode 1: Mock Mode (No API Keys Required)
|
|
616
|
+
|
|
617
|
+
Use this for **testing, benchmarking, and development**. The mock model pattern-matches your question against 12 pre-defined LUBM queries:
|
|
618
|
+
|
|
619
|
+
```typescript
|
|
620
|
+
const { HyperMindAgent } = require('rust-kgdb')
|
|
621
|
+
|
|
622
|
+
// Spawn agent with mock model - NO API KEYS NEEDED
|
|
623
|
+
const agent = await HyperMindAgent.spawn({
|
|
624
|
+
name: 'test-agent',
|
|
625
|
+
model: 'mock', // Uses pattern matching, not LLM
|
|
626
|
+
tools: ['kg.sparql.query'],
|
|
627
|
+
endpoint: 'http://localhost:30080' // Your rust-kgdb endpoint
|
|
628
|
+
})
|
|
629
|
+
|
|
630
|
+
// Ask a question (pattern-matched to LUBM queries)
|
|
631
|
+
const result = await agent.call('Find all professors in the database')
|
|
632
|
+
|
|
633
|
+
console.log(result.success) // true
|
|
634
|
+
console.log(result.sparql) // "PREFIX ub: <...> SELECT ?x WHERE { ?x a ub:Professor }"
|
|
635
|
+
console.log(result.results) // Query results from your database
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
**Supported Mock Questions (12 LUBM patterns):**
|
|
639
|
+
| Question Pattern | Generated SPARQL |
|
|
640
|
+
|-----------------|------------------|
|
|
641
|
+
| "Find all professors..." | `SELECT ?x WHERE { ?x a ub:Professor }` |
|
|
642
|
+
| "List all graduate students" | `SELECT ?x WHERE { ?x a ub:GraduateStudent }` |
|
|
643
|
+
| "How many courses..." | `SELECT (COUNT(?x) AS ?count) WHERE { ?x a ub:Course }` |
|
|
644
|
+
| "Find students and their advisors" | `SELECT ?student ?advisor WHERE { ?student ub:advisor ?advisor }` |
|
|
645
|
+
|
|
646
|
+
### Mode 2: LLM Mode (Requires API Keys)
|
|
647
|
+
|
|
648
|
+
Use this for **production** with real LLM-powered query generation:
|
|
649
|
+
|
|
650
|
+
```bash
|
|
651
|
+
# Set environment variables BEFORE running your code
|
|
652
|
+
export ANTHROPIC_API_KEY="sk-ant-api03-..." # For Claude
|
|
653
|
+
export OPENAI_API_KEY="sk-proj-..." # For GPT-4o
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
```typescript
|
|
657
|
+
const { HyperMindAgent } = require('rust-kgdb')
|
|
658
|
+
|
|
659
|
+
// Spawn agent with Claude (requires ANTHROPIC_API_KEY)
|
|
660
|
+
const agent = await HyperMindAgent.spawn({
|
|
661
|
+
name: 'prod-agent',
|
|
662
|
+
model: 'claude-sonnet-4', // Real LLM - generates dynamic SPARQL
|
|
663
|
+
tools: ['kg.sparql.query', 'kg.motif.find'],
|
|
664
|
+
endpoint: 'http://localhost:30080'
|
|
665
|
+
})
|
|
666
|
+
|
|
667
|
+
// Any natural language question works (not limited to patterns)
|
|
668
|
+
const result = await agent.call('Find professors who teach AI and have more than 5 publications')
|
|
669
|
+
|
|
670
|
+
// LLM generates appropriate SPARQL dynamically
|
|
671
|
+
console.log(result.sparql) // Complex query generated by Claude
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
**Supported LLM Models:**
|
|
675
|
+
| Model | Environment Variable | Use Case |
|
|
676
|
+
|-------|---------------------|----------|
|
|
677
|
+
| `claude-sonnet-4` | `ANTHROPIC_API_KEY` | Best accuracy |
|
|
678
|
+
| `gpt-4o` | `OPENAI_API_KEY` | Alternative |
|
|
679
|
+
| `mock` | None | Testing only |
|
|
680
|
+
|
|
681
|
+
### Run the Benchmark
|
|
682
|
+
|
|
683
|
+
```typescript
|
|
684
|
+
const { runHyperMindBenchmark } = require('rust-kgdb')
|
|
685
|
+
|
|
686
|
+
// Test with mock model (no API keys)
|
|
687
|
+
const stats = await runHyperMindBenchmark('http://localhost:30080', 'mock', {
|
|
688
|
+
saveResults: true // Saves JSON file with results
|
|
689
|
+
})
|
|
690
|
+
|
|
691
|
+
console.log(`Success: ${stats.syntaxSuccess}/${stats.totalTests}`) // 12/12
|
|
692
|
+
console.log(`Latency: ${stats.avgLatencyMs.toFixed(1)}ms`) // ~6.58ms
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
### Important: Embeddings Are Separate
|
|
696
|
+
|
|
697
|
+
**HyperMind agents do NOT use embeddings for query generation.** Embeddings are a separate feature for semantic similarity search:
|
|
698
|
+
|
|
699
|
+
```typescript
|
|
700
|
+
const { EmbeddingService, GraphDB } = require('rust-kgdb')
|
|
701
|
+
|
|
702
|
+
// Embeddings: For semantic similarity search (SEPARATE from HyperMind)
|
|
703
|
+
const embeddings = new EmbeddingService({ provider: 'mock', dimensions: 384 })
|
|
704
|
+
embeddings.addText('professor', 'A teacher at a university')
|
|
705
|
+
embeddings.addText('student', 'Someone who studies at a university')
|
|
706
|
+
const similar = embeddings.findSimilar('teacher', 5) // Finds "professor"
|
|
707
|
+
|
|
708
|
+
// HyperMind: For natural language to SPARQL (NO embeddings used)
|
|
709
|
+
const agent = await HyperMindAgent.spawn({ model: 'mock', ... })
|
|
710
|
+
const result = await agent.call('Find professors') // Generates SPARQL query
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
| Feature | HyperMind Agent | Embedding Service |
|
|
714
|
+
|---------|-----------------|-------------------|
|
|
715
|
+
| **Purpose** | NL → SPARQL queries | Semantic similarity |
|
|
716
|
+
| **Input** | Natural language question | Text to embed |
|
|
717
|
+
| **Output** | SPARQL query + results | Similar items |
|
|
718
|
+
| **Uses embeddings?** | No | Yes |
|
|
719
|
+
| **Requires API key?** | Only for LLM mode | No (mock available) |
|
|
720
|
+
|
|
584
721
|
### Architecture Overview
|
|
585
722
|
|
|
586
723
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rust-kgdb",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
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",
|