rust-kgdb 0.6.83 → 0.6.84

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.archive.md DELETED
@@ -1,2632 +0,0 @@
1
- # rust-kgdb
2
-
3
- [![npm version](https://img.shields.io/npm/v/rust-kgdb.svg)](https://www.npmjs.com/package/rust-kgdb)
4
- [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5
- [![W3C](https://img.shields.io/badge/W3C-SPARQL%201.1%20%7C%20RDF%201.2-blue)](https://www.w3.org/TR/sparql11-query/)
6
-
7
- > **Two-Layer Architecture**: High-performance Rust knowledge graph database + HyperMind neuro-symbolic agent framework with mathematical foundations.
8
-
9
- ---
10
-
11
- ## The Problem
12
-
13
- We asked GPT-4 to write a simple SPARQL query: *"Find all professors."*
14
-
15
- It returned this broken output:
16
-
17
- ```text
18
- ```sparql
19
- SELECT ?professor WHERE { ?professor a ub:Faculty . }
20
- ```
21
- This query retrieves faculty members from the knowledge graph.
22
- ```
23
-
24
- Three problems: (1) markdown code fences break the parser, (2) `ub:Faculty` doesn't exist in the schema (it's `ub:Professor`), and (3) the explanation text is mixed with the query. **Result: Parser error. Zero results.**
25
-
26
- This isn't a cherry-picked failure. When we ran the standard LUBM benchmark (14 queries, 3,272 triples), vanilla LLMs produced valid, correct SPARQL **0% of the time**.
27
-
28
- We built rust-kgdb to fix this.
29
-
30
- ---
31
-
32
- ## Architecture: What Powers rust-kgdb
33
-
34
- ```
35
- ┌─────────────────────────────────────────────────────────────────────────────────┐
36
- │ YOUR APPLICATION │
37
- │ (Fraud Detection, Underwriting, Compliance) │
38
- └────────────────────────────────────┬────────────────────────────────────────────┘
39
-
40
- ┌────────────────────────────────────▼────────────────────────────────────────────┐
41
- │ HYPERMIND AGENT FRAMEWORK (SDK Layer) │
42
- │ ┌────────────────────────────────────────────────────────────────────────────┐ │
43
- │ │ Mathematical Abstractions (High-Level) │ │
44
- │ │ • TypeId: Hindley-Milner type system with refinement types │ │
45
- │ │ • LLMPlanner: Natural language → typed tool pipelines │ │
46
- │ │ • WasmSandbox: WASM isolation with capability-based security │ │
47
- │ │ • AgentBuilder: Fluent composition of typed tools │ │
48
- │ │ • ExecutionWitness: Cryptographic proofs (SHA-256) │ │
49
- │ └────────────────────────────────────────────────────────────────────────────┘ │
50
- │ │ │
51
- │ Category Theory: Tools as Morphisms (A → B) │
52
- │ Proof Theory: Every execution has a witness │
53
- └────────────────────────────────────┬────────────────────────────────────────────┘
54
- │ NAPI-RS Bindings
55
- ┌────────────────────────────────────▼────────────────────────────────────────────┐
56
- │ RUST CORE ENGINE (Native Performance) │
57
- │ ┌────────────────────────────────────────────────────────────────────────────┐ │
58
- │ │ GraphDB │ RDF/SPARQL quad store │ 2.78µs lookups, 24 bytes/triple│
59
- │ │ GraphFrame │ Graph algorithms │ WCOJ optimal joins, PageRank │
60
- │ │ EmbeddingService │ Vector similarity │ HNSW index, 1-hop ARCADE cache│
61
- │ │ DatalogProgram │ Rule-based reasoning │ Semi-naive evaluation │
62
- │ │ Pregel │ BSP graph processing │ Iterative algorithms │
63
- │ └────────────────────────────────────────────────────────────────────────────┘ │
64
- │ │
65
- │ W3C Standards: SPARQL 1.1 (100%) | RDF 1.2 | OWL 2 RL | SHACL | RDFS │
66
- │ Storage Backends: InMemory | RocksDB | LMDB │
67
- │ Distribution: HDRF Partitioning | Raft Consensus | gRPC │
68
- └──────────────────────────────────────────────────────────────────────────────────┘
69
- ```
70
-
71
- **Key Insight**: The Rust core provides raw performance (2.78µs lookups). The HyperMind framework adds mathematical guarantees (type safety, composition laws, proof generation) without sacrificing speed.
72
-
73
- ### What's Rust Core vs SDK Layer?
74
-
75
- All major capabilities are implemented in **Rust** via the HyperMind SDK crates (`hypermind-types`, `hypermind-runtime`, `hypermind-sdk`). The JavaScript/TypeScript layer is a thin binding that exposes these Rust capabilities for Node.js applications.
76
-
77
- | Component | Implementation | Performance | Notes |
78
- |-----------|---------------|-------------|-------|
79
- | **GraphDB** | Rust via NAPI-RS | 2.78µs lookups | Zero-copy RDF quad store |
80
- | **GraphFrame** | Rust via NAPI-RS | WCOJ optimal | PageRank, triangles, components |
81
- | **EmbeddingService** | Rust via NAPI-RS | Sub-ms search | HNSW index + 1-hop cache |
82
- | **DatalogProgram** | Rust via NAPI-RS | Semi-naive eval | Rule-based reasoning |
83
- | **Pregel** | Rust via NAPI-RS | BSP model | Iterative graph algorithms |
84
- | **TypeId** | Rust via NAPI-RS | N/A | Hindley-Milner type system |
85
- | **LLMPlanner** | JavaScript + HTTP | LLM latency | Orchestrates Rust tools via Claude/GPT |
86
- | **WasmSandbox** | Rust via NAPI-RS | Capability check | WASM isolation runtime |
87
- | **AgentBuilder** | Rust via NAPI-RS | N/A | Fluent tool composition |
88
- | **ExecutionWitness** | Rust via NAPI-RS | SHA-256 | Cryptographic audit proofs |
89
-
90
- **Security Model**: All interactions with Rust components flow through NAPI-RS bindings with memory isolation. The WasmSandbox wraps these bindings with capability-based access control, ensuring agents can only invoke tools they're explicitly granted. This provides defense-in-depth: NAPI-RS for memory safety, WasmSandbox for capability control.
91
-
92
- ---
93
-
94
- ## The Solution
95
-
96
- rust-kgdb is a knowledge graph database with a neuro-symbolic agent framework called **HyperMind**. Instead of hoping the LLM gets the syntax right, we use mathematical type theory to *guarantee* correctness.
97
-
98
- The same query through HyperMind:
99
-
100
- ```sparql
101
- PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
102
- SELECT ?professor WHERE { ?professor a ub:Professor . }
103
- ```
104
-
105
- **Result: 15 professors returned in 2.3ms.**
106
-
107
- The difference? HyperMind treats tools as **typed morphisms** (category theory), validates queries at **compile-time** (type theory), and produces **cryptographic witnesses** for every execution (proof theory). The LLM plans; the math executes.
108
-
109
- **Accuracy improvement: 0% → 86.4%** on the LUBM benchmark.
110
-
111
- ---
112
-
113
- ## The Deeper Problem: AI Agents Forget
114
-
115
- Fixing SPARQL syntax is table stakes. Here's what keeps enterprise architects up at night:
116
-
117
- **Scenario**: Your fraud detection agent correctly identified a circular payment ring last Tuesday. Today, an analyst asks: *"Show me similar patterns to what we found last week."*
118
-
119
- The LLM response: *"I don't have access to previous conversations. Can you describe what you're looking for?"*
120
-
121
- **The agent forgot everything.**
122
-
123
- Every enterprise AI deployment hits the same wall:
124
- - **No Memory**: Each session starts from zero - expensive recomputation, no learning
125
- - **No Context Window Management**: Hit token limits? Lose critical history
126
- - **No Idempotent Responses**: Same question, different answer - compliance nightmare
127
- - **No Provenance Chain**: "Why did the agent flag this claim?" - silence
128
-
129
- LangChain's solution: Vector databases. Store conversations, retrieve via similarity.
130
-
131
- **The problem**: Similarity isn't memory. When your underwriter asks *"What did we decide about claims from Provider X?"*, you need:
132
- 1. **Temporal awareness** - What we decided *last month* vs *yesterday*
133
- 2. **Semantic edges** - The decision *relates to* these specific claims
134
- 3. **Epistemological stratification** - Fact vs inference vs hypothesis
135
- 4. **Proof chain** - *Why* we decided this, not just *that* we did
136
-
137
- This requires a **Memory Hypergraph** - not a vector store.
138
-
139
- ---
140
-
141
- ## Memory Hypergraph: How AI Agents Remember
142
-
143
- rust-kgdb introduces the **Memory Hypergraph** - a temporal knowledge graph where agent memory is stored in the *same* quad store as your domain knowledge, with hyper-edges connecting episodes to KG entities.
144
-
145
- ```
146
- ┌─────────────────────────────────────────────────────────────────────────────────┐
147
- │ MEMORY HYPERGRAPH ARCHITECTURE │
148
- │ │
149
- │ ┌─────────────────────────────────────────────────────────────────────────┐ │
150
- │ │ AGENT MEMORY LAYER (am: graph) │ │
151
- │ │ │ │
152
- │ │ Episode:001 Episode:002 Episode:003 │ │
153
- │ │ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │ │
154
- │ │ │ Fraud ring │ │ Underwriting │ │ Follow-up │ │ │
155
- │ │ │ detected in │ │ denied claim │ │ investigation │ │ │
156
- │ │ │ Provider P001 │ │ from P001 │ │ on P001 │ │ │
157
- │ │ │ │ │ │ │ │ │ │
158
- │ │ │ Dec 10, 14:30 │ │ Dec 12, 09:15 │ │ Dec 15, 11:00 │ │ │
159
- │ │ │ Score: 0.95 │ │ Score: 0.87 │ │ Score: 0.92 │ │ │
160
- │ │ └───────┬───────┘ └───────┬───────┘ └───────┬───────┘ │ │
161
- │ │ │ │ │ │ │
162
- │ └───────────┼─────────────────────────┼─────────────────────────┼─────────┘ │
163
- │ │ HyperEdge: │ HyperEdge: │ │
164
- │ │ "QueriedKG" │ "DeniedClaim" │ │
165
- │ ▼ ▼ ▼ │
166
- │ ┌─────────────────────────────────────────────────────────────────────────┐ │
167
- │ │ KNOWLEDGE GRAPH LAYER (domain graph) │ │
168
- │ │ │ │
169
- │ │ Provider:P001 ──────────────▶ Claim:C123 ◀────────── Claimant:C001 │ │
170
- │ │ │ │ │ │ │
171
- │ │ │ :hasRiskScore │ :amount │ :name │ │
172
- │ │ ▼ ▼ ▼ │ │
173
- │ │ "0.87" "50000" "John Doe" │ │
174
- │ │ │ │
175
- │ │ ┌─────────────────────────────────────────────────────────────┐ │ │
176
- │ │ │ SAME QUAD STORE - Single SPARQL query traverses BOTH │ │ │
177
- │ │ │ memory graph AND knowledge graph! │ │ │
178
- │ │ └─────────────────────────────────────────────────────────────┘ │ │
179
- │ │ │ │
180
- │ └─────────────────────────────────────────────────────────────────────────┘ │
181
- │ │
182
- │ ┌─────────────────────────────────────────────────────────────────────────┐ │
183
- │ │ TEMPORAL SCORING FORMULA │ │
184
- │ │ │ │
185
- │ │ Score = α × Recency + β × Relevance + γ × Importance │ │
186
- │ │ │ │
187
- │ │ where: │ │
188
- │ │ Recency = 0.995^hours (12% decay/day) │ │
189
- │ │ Relevance = cosine_similarity(query, episode) │ │
190
- │ │ Importance = log10(access_count + 1) / log10(max + 1) │ │
191
- │ │ │ │
192
- │ │ Default: α=0.3, β=0.5, γ=0.2 │ │
193
- │ └─────────────────────────────────────────────────────────────────────────┘ │
194
- │ │
195
- └─────────────────────────────────────────────────────────────────────────────────┘
196
- ```
197
-
198
- ### Why This Matters for Enterprise AI
199
-
200
- **Without Memory Hypergraph** (LangChain, LlamaIndex):
201
- ```javascript
202
- // Ask about last week's findings
203
- agent.chat("What fraud patterns did we find with Provider P001?")
204
- // Response: "I don't have that information. Could you describe what you're looking for?"
205
- // Cost: Re-run entire fraud detection pipeline ($5 in API calls, 30 seconds)
206
- ```
207
-
208
- **With Memory Hypergraph** (rust-kgdb HyperMind Framework):
209
- ```javascript
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
- })
216
-
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 .
244
- }
245
- ?claim :provider ?provider ; :amount ?claimAmount .
246
- FILTER(?claimAmount > 25000)
247
- }
248
- ```
249
- *You never write this - the typed API builds it for you.*
250
-
251
- ### Rolling Context Window
252
-
253
- Token limits are real. rust-kgdb uses a **rolling time window strategy** to find the right context:
254
-
255
- ```
256
- ┌─────────────────────────────────────────────────────────────────────────────────┐
257
- │ ROLLING CONTEXT WINDOW │
258
- │ │
259
- │ Query: "What did we find about Provider P001?" │
260
- │ │
261
- │ Pass 1: Search last 1 hour → 0 episodes found → expand │
262
- │ Pass 2: Search last 24 hours → 1 episode found (not enough) → expand │
263
- │ Pass 3: Search last 7 days → 3 episodes found → within token budget ✓ │
264
- │ │
265
- │ Context returned: │
266
- │ ┌──────────────────────────────────────────────────────────────────────────┐ │
267
- │ │ Episode 003 (Dec 15): "Follow-up investigation on P001..." │ │
268
- │ │ Episode 002 (Dec 12): "Underwriting denied claim from P001..." │ │
269
- │ │ Episode 001 (Dec 10): "Fraud ring detected in Provider P001..." │ │
270
- │ │ │ │
271
- │ │ Estimated tokens: 847 / 8192 max │ │
272
- │ │ Time window: 7 days │ │
273
- │ │ Search passes: 3 │ │
274
- │ └──────────────────────────────────────────────────────────────────────────┘ │
275
- │ │
276
- └─────────────────────────────────────────────────────────────────────────────────┘
277
- ```
278
-
279
- ### Idempotent Responses via Semantic Hashing
280
-
281
- Same question = Same answer. Even with **different wording**. Critical for compliance.
282
-
283
- ```javascript
284
- // First call: Compute answer, cache with semantic hash
285
- const result1 = await agent.call("Analyze claims from Provider P001")
286
- // Semantic Hash: semhash:fraud-provider-p001-claims-analysis
287
-
288
- // Second call (different wording, same intent): Cache HIT!
289
- const result2 = await agent.call("Show me P001's claim patterns")
290
- // Cache HIT - same semantic hash: semhash:fraud-provider-p001-claims-analysis
291
-
292
- // Third call (exact same): Also cache hit
293
- const result3 = await agent.call("Analyze claims from Provider P001")
294
- // Cache HIT - same semantic hash: semhash:fraud-provider-p001-claims-analysis
295
-
296
- // Compliance officer: "Why are these identical?"
297
- // You: "Semantic hashing - same meaning, same output, regardless of phrasing."
298
- ```
299
-
300
- **How it works**: Query embeddings are hashed via **Locality-Sensitive Hashing (LSH)** with random hyperplane projections. Semantically similar queries map to the same bucket.
301
-
302
- **Research Foundation**:
303
- - **SimHash** (Charikar, 2002) - Random hyperplane projections for cosine similarity
304
- - **Semantic Hashing** (Salakhutdinov & Hinton, 2009) - Deep autoencoders for binary codes
305
- - **Learning to Hash** (Wang et al., 2018) - Survey of neural hashing methods
306
-
307
- **Implementation**: 384-dim embeddings → LSH with 64 hyperplanes → 64-bit semantic hash
308
-
309
- **Benefits**:
310
- - **Semantic deduplication** - "Find fraud" and "Detect fraudulent activity" hit same cache
311
- - **Cost reduction** - Avoid redundant LLM calls for paraphrased questions
312
- - **Consistency** - Same answer for same intent, audit-ready
313
- - **Sub-linear lookup** - O(1) hash lookup vs O(n) embedding comparison
314
-
315
- ---
316
-
317
- ## What This Is
318
-
319
- **World's first mobile-native knowledge graph database with clustered distribution and mathematically-grounded HyperMind agent framework.**
320
-
321
- Most graph databases were designed for servers. Most AI agents are built on prompt engineering and hope. We built both from the ground up - the database for performance, the agent framework for correctness:
322
-
323
- 1. **Mobile-First**: Runs natively on iOS and Android with zero-copy FFI
324
- 2. **Standalone + Clustered**: Same codebase scales from smartphone to Kubernetes
325
- 3. **Open Standards**: W3C SPARQL 1.1, RDF 1.2, OWL 2 RL, SHACL - no vendor lock-in
326
- 4. **Mathematical Foundations**: Type theory, category theory, proof theory - not prompt engineering
327
- 5. **Worst-Case Optimal Joins**: WCOJ algorithm guarantees O(N^(ρ/2)) complexity
328
-
329
- ---
330
-
331
- ## Published Benchmarks
332
-
333
- We don't make claims we can't prove. All measurements use **publicly available, peer-reviewed benchmarks**.
334
-
335
- **Public Benchmarks Used:**
336
- - **LUBM** (Lehigh University Benchmark) - Standard RDF/SPARQL benchmark since 2005
337
- - **SP2Bench** - DBLP-based SPARQL performance benchmark
338
- - **W3C SPARQL 1.1 Conformance Suite** - Official W3C test cases
339
-
340
- | Metric | Value | Why It Matters |
341
- |--------|-------|----------------|
342
- | **Lookup Latency** | 2.78 µs | 35x faster than RDFox |
343
- | **Memory per Triple** | 24 bytes | 25% more efficient than RDFox |
344
- | **Bulk Insert** | 146K triples/sec | Production-ready throughput |
345
- | **SPARQL Accuracy** | 86.4% | vs 0% vanilla LLM (LUBM benchmark) |
346
- | **W3C Compliance** | 100% | Full SPARQL 1.1 + RDF 1.2 |
347
-
348
- ### How We Measured
349
-
350
- - **Dataset**: LUBM benchmark (industry standard since 2005)
351
- - **Hardware**: Apple Silicon M2 MacBook Pro
352
- - **Methodology**: 10,000+ iterations, cold-start, statistical analysis
353
- - **Comparison**: Apache Jena 4.x, RDFox 7.x under identical conditions
354
-
355
- **Try it yourself:**
356
- ```bash
357
- node hypermind-benchmark.js # Compare HyperMind vs Vanilla LLM accuracy
358
- ```
359
-
360
- ---
361
-
362
- ## Why Embeddings? The Rise of Neuro-Symbolic AI
363
-
364
- ### The Problem with Pure Symbolic Systems
365
-
366
- Traditional knowledge graphs are powerful for **structured reasoning**:
367
-
368
- ```sparql
369
- SELECT ?fraud WHERE {
370
- ?claim :amount ?amt .
371
- FILTER(?amt > 50000)
372
- ?claim :provider ?prov .
373
- ?prov :flaggedCount ?flags .
374
- FILTER(?flags > 3)
375
- }
376
- ```
377
-
378
- But they fail at **semantic similarity**: "Find claims similar to this suspicious one" requires understanding meaning, not just matching predicates.
379
-
380
- ### The Problem with Pure Neural Systems
381
-
382
- LLMs and embedding models excel at **semantic understanding**:
383
-
384
- ```javascript
385
- // Find semantically similar claims
386
- const similar = embeddings.findSimilar('CLM001', 10, 0.85)
387
- ```
388
-
389
- But they hallucinate, have no audit trail, and can't explain their reasoning.
390
-
391
- ### The Neuro-Symbolic Solution
392
-
393
- **rust-kgdb combines both**: Use embeddings for semantic discovery, symbolic reasoning for provable conclusions.
394
-
395
- ```
396
- ┌─────────────────────────────────────────────────────────────────────────┐
397
- │ NEURO-SYMBOLIC PIPELINE │
398
- │ │
399
- │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
400
- │ │ NEURAL │ │ SYMBOLIC │ │ NEURAL │ │
401
- │ │ (Discovery) │ ───▶ │ (Reasoning) │ ───▶ │ (Explain) │ │
402
- │ └──────────────┘ └──────────────┘ └──────────────┘ │
403
- │ │
404
- │ "Find similar" "Apply rules" "Summarize for │
405
- │ Embeddings search Datalog inference human consumption" │
406
- │ HNSW index Semi-naive eval LLM generation │
407
- │ Sub-ms latency Deterministic Cryptographic proof │
408
- └─────────────────────────────────────────────────────────────────────────┘
409
- ```
410
-
411
- ### Why 1-Hop Embeddings Matter
412
-
413
- The ARCADE (Adaptive Relation-Aware Cache for Dynamic Embeddings) algorithm provides **1-hop neighbor awareness**:
414
-
415
- ```javascript
416
- const service = new EmbeddingService()
417
-
418
- // Build neighbor cache from triples
419
- service.onTripleInsert('CLM001', 'claimant', 'P001', null)
420
- service.onTripleInsert('P001', 'knows', 'P002', null)
421
-
422
- // 1-hop aware similarity: finds entities connected in the graph
423
- const neighbors = service.getNeighborsOut('P001') // ['P002']
424
-
425
- // Combine structural + semantic similarity
426
- // "Find similar claims that are also connected to this claimant"
427
- ```
428
-
429
- **Why it matters**: Pure embedding similarity finds semantically similar entities. 1-hop awareness finds entities that are both similar AND structurally connected - critical for fraud ring detection where relationships matter as much as content.
430
-
431
- ---
432
-
433
- ## Embedding Service: Multi-Provider Vector Search
434
-
435
- ### Provider Abstraction
436
-
437
- The EmbeddingService supports multiple embedding providers with a unified API:
438
-
439
- ```javascript
440
- const { EmbeddingService } = require('rust-kgdb')
441
-
442
- // Initialize service (uses built-in 384-dim embeddings by default)
443
- const service = new EmbeddingService()
444
-
445
- // Store embeddings from any provider
446
- service.storeVector('entity1', openaiEmbedding) // 384-dim
447
- service.storeVector('entity2', anthropicEmbedding) // 384-dim
448
- service.storeVector('entity3', cohereEmbedding) // 384-dim
449
-
450
- // HNSW similarity search (Rust-native, sub-ms)
451
- service.rebuildIndex()
452
- const similar = JSON.parse(service.findSimilar('entity1', 10, 0.7))
453
- ```
454
-
455
- ### Composite Multi-Provider Embeddings
456
-
457
- For production deployments, combine multiple providers for robustness:
458
-
459
- ```javascript
460
- // Store embeddings from multiple providers for the same entity
461
- service.storeComposite('CLM001', JSON.stringify({
462
- openai: await openai.embed('Insurance claim for soft tissue injury'),
463
- voyage: await voyage.embed('Insurance claim for soft tissue injury'),
464
- cohere: await cohere.embed('Insurance claim for soft tissue injury')
465
- }))
466
-
467
- // Search with aggregation strategies
468
- const rrfResults = service.findSimilarComposite('CLM001', 10, 0.7, 'rrf') // Reciprocal Rank Fusion
469
- const maxResults = service.findSimilarComposite('CLM001', 10, 0.7, 'max') // Max score
470
- const voteResults = service.findSimilarComposite('CLM001', 10, 0.7, 'voting') // Majority voting
471
- ```
472
-
473
- ### Provider Configuration
474
-
475
- rust-kgdb's `EmbeddingService` stores and searches vectors - you bring your own embeddings from any provider. Here are examples using popular third-party libraries:
476
-
477
- ```javascript
478
- // ============================================================
479
- // EXAMPLE: Using OpenAI embeddings (requires: npm install openai)
480
- // ============================================================
481
- const { OpenAI } = require('openai') // Third-party library
482
- const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY })
483
-
484
- async function getOpenAIEmbedding(text) {
485
- const response = await openai.embeddings.create({
486
- model: 'text-embedding-3-small',
487
- input: text,
488
- dimensions: 384 // Match rust-kgdb's 384-dim format
489
- })
490
- return response.data[0].embedding
491
- }
492
-
493
- // ============================================================
494
- // EXAMPLE: Using Voyage AI (requires: npm install voyageai)
495
- // Note: Anthropic recommends Voyage AI for embeddings
496
- // ============================================================
497
- async function getVoyageEmbedding(text) {
498
- // Using fetch directly (no SDK required)
499
- const response = await fetch('https://api.voyageai.com/v1/embeddings', {
500
- method: 'POST',
501
- headers: {
502
- 'Authorization': `Bearer ${process.env.VOYAGE_API_KEY}`,
503
- 'Content-Type': 'application/json'
504
- },
505
- body: JSON.stringify({ input: text, model: 'voyage-2' })
506
- })
507
- const data = await response.json()
508
- return data.data[0].embedding.slice(0, 384) // Truncate to 384-dim
509
- }
510
-
511
- // ============================================================
512
- // EXAMPLE: Mock embeddings for testing (no external deps)
513
- // ============================================================
514
- function getMockEmbedding(text) {
515
- return new Array(384).fill(0).map((_, i) =>
516
- Math.sin(text.charCodeAt(i % text.length) * 0.1) * 0.5 + 0.5
517
- )
518
- }
519
- ```
520
-
521
- ---
522
-
523
- ## Graph Ingestion Pipeline with Embedding Triggers
524
-
525
- ### Automatic Embedding on Triple Insert
526
-
527
- Configure your pipeline to automatically generate embeddings when triples are inserted:
528
-
529
- ```javascript
530
- const { GraphDB, EmbeddingService } = require('rust-kgdb')
531
-
532
- // Initialize services
533
- const db = new GraphDB('http://insurance.org/claims')
534
- const embeddings = new EmbeddingService()
535
-
536
- // Embedding provider (configure with your API key)
537
- async function getEmbedding(text) {
538
- // Replace with your provider (OpenAI, Voyage, Cohere, etc.)
539
- return new Array(384).fill(0).map(() => Math.random())
540
- }
541
-
542
- // Ingestion pipeline with embedding triggers
543
- async function ingestClaim(claim) {
544
- // 1. Insert structured data into knowledge graph
545
- db.loadTtl(`
546
- @prefix : <http://insurance.org/> .
547
- :${claim.id} a :Claim ;
548
- :amount "${claim.amount}" ;
549
- :description "${claim.description}" ;
550
- :claimant :${claim.claimantId} ;
551
- :provider :${claim.providerId} .
552
- `, null)
553
-
554
- // 2. Generate and store embedding for semantic search
555
- const vector = await getEmbedding(claim.description)
556
- embeddings.storeVector(claim.id, vector)
557
-
558
- // 3. Update 1-hop cache for neighbor-aware search
559
- embeddings.onTripleInsert(claim.id, 'claimant', claim.claimantId, null)
560
- embeddings.onTripleInsert(claim.id, 'provider', claim.providerId, null)
561
-
562
- // 4. Rebuild index after batch inserts (or periodically)
563
- embeddings.rebuildIndex()
564
-
565
- return { tripleCount: db.countTriples(), embeddingStored: true }
566
- }
567
-
568
- // Process batch with embedding triggers
569
- async function processBatch(claims) {
570
- for (const claim of claims) {
571
- await ingestClaim(claim)
572
- console.log(`Ingested: ${claim.id}`)
573
- }
574
-
575
- // Rebuild HNSW index after batch
576
- embeddings.rebuildIndex()
577
- console.log(`Index rebuilt with ${claims.length} new embeddings`)
578
- }
579
- ```
580
-
581
- ### Pipeline Architecture
582
-
583
- ```
584
- ┌─────────────────────────────────────────────────────────────────────────┐
585
- │ GRAPH INGESTION PIPELINE │
586
- │ │
587
- │ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │
588
- │ │ Data Source │ │ Transform │ │ Enrich │ │
589
- │ │ (JSON/CSV) │────▶│ (to RDF) │────▶│ (+Embeddings)│ │
590
- │ └───────────────┘ └───────────────┘ └───────┬───────┘ │
591
- │ │ │
592
- │ ┌───────────────────────────────────────────────────┼───────────────┐ │
593
- │ │ TRIGGERS │ │ │
594
- │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┴─────────────┐ │ │
595
- │ │ │ Embedding │ │ 1-Hop │ │ HNSW Index │ │ │
596
- │ │ │ Generation │ │ Cache │ │ Rebuild │ │ │
597
- │ │ │ (per entity)│ │ Update │ │ (batch/periodic) │ │ │
598
- │ │ └─────────────┘ └─────────────┘ └───────────────────────────┘ │ │
599
- │ └───────────────────────────────────────────────────────────────────┘ │
600
- │ │ │
601
- │ ▼ │
602
- │ ┌───────────────────────────────────────────────────────────────────┐ │
603
- │ │ RUST CORE (NAPI-RS) │ │
604
- │ │ GraphDB (triples) │ EmbeddingService (vectors) │ HNSW (index) │ │
605
- │ └───────────────────────────────────────────────────────────────────┘ │
606
- └─────────────────────────────────────────────────────────────────────────┘
607
- ```
608
-
609
- ---
610
-
611
- ## HyperAgent Framework Components
612
-
613
- The HyperMind agent framework provides complete infrastructure for building neuro-symbolic AI agents:
614
-
615
- ### Architecture Overview
616
-
617
- ```
618
- ┌─────────────────────────────────────────────────────────────────────────┐
619
- │ HYPERAGENT FRAMEWORK │
620
- │ │
621
- │ ┌─────────────────────────────────────────────────────────────────┐ │
622
- │ │ GOVERNANCE LAYER │ │
623
- │ │ Policy Engine | Capability Grants | Audit Trail | Compliance │ │
624
- │ └─────────────────────────────────────────────────────────────────┘ │
625
- │ │ │
626
- │ ┌───────────────────────────────┼─────────────────────────────────┐ │
627
- │ │ RUNTIME LAYER │ │
628
- │ │ ┌──────────────┐ ┌───────┴───────┐ ┌──────────────┐ │ │
629
- │ │ │ LLMPlanner │ │ PlanExecutor │ │ WasmSandbox │ │ │
630
- │ │ │ (Claude/GPT)│───▶│ (Type-safe) │───▶│ (Isolated) │ │ │
631
- │ │ └──────────────┘ └───────────────┘ └──────┬───────┘ │ │
632
- │ └──────────────────────────────────────────────────┼──────────────┘ │
633
- │ │ │
634
- │ ┌──────────────────────────────────────────────────┼──────────────┐ │
635
- │ │ PROXY LAYER │ │ │
636
- │ │ Object Proxy: All tool calls flow through typed morphism layer │ │
637
- │ │ ┌────────────────────────────────────────────────┴───────────┐ │ │
638
- │ │ │ proxy.call('kg.sparql.query', { query }) → BindingSet │ │ │
639
- │ │ │ proxy.call('kg.motif.find', { pattern }) → List<Match> │ │ │
640
- │ │ │ proxy.call('kg.datalog.infer', { rules }) → List<Fact> │ │ │
641
- │ │ │ proxy.call('kg.embeddings.search', { entity }) → Similar │ │ │
642
- │ │ └────────────────────────────────────────────────────────────┘ │ │
643
- │ └─────────────────────────────────────────────────────────────────┘ │
644
- │ │
645
- │ ┌─────────────────────────────────────────────────────────────────┐ │
646
- │ │ MEMORY LAYER │ │
647
- │ │ Working Memory | Long-term Memory | Episodic Memory │ │
648
- │ │ (Current context) (Knowledge graph) (Execution history) │ │
649
- │ └─────────────────────────────────────────────────────────────────┘ │
650
- │ │
651
- │ ┌─────────────────────────────────────────────────────────────────┐ │
652
- │ │ SCOPE LAYER │ │
653
- │ │ Namespace isolation | Resource limits | Capability boundaries │ │
654
- │ └─────────────────────────────────────────────────────────────────┘ │
655
- └─────────────────────────────────────────────────────────────────────────┘
656
- ```
657
-
658
- ### Component Details
659
-
660
- **Governance Layer**: Policy-based control over agent behavior
661
- ```javascript
662
- const agent = new AgentBuilder('compliance-agent')
663
- .withPolicy({
664
- maxExecutionTime: 30000, // 30 second timeout
665
- allowedTools: ['kg.sparql.query', 'kg.datalog.infer'],
666
- deniedTools: ['kg.update', 'kg.delete'], // Read-only
667
- auditLevel: 'full' // Log all tool calls
668
- })
669
- ```
670
-
671
- **Runtime Layer**: Type-safe plan execution
672
- ```javascript
673
- const { LLMPlanner, TOOL_REGISTRY } = require('rust-kgdb/hypermind-agent')
674
-
675
- const planner = new LLMPlanner('claude-sonnet-4', TOOL_REGISTRY)
676
- const plan = await planner.plan("Find suspicious claims")
677
- // plan.steps: [{tool: 'kg.sparql.query', args: {...}}, ...]
678
- // plan.confidence: 0.92
679
- ```
680
-
681
- **Proxy Layer**: All Rust interactions through typed morphisms
682
- ```javascript
683
- const sandbox = new WasmSandbox({
684
- capabilities: ['ReadKG', 'ExecuteTool'],
685
- fuelLimit: 1000000
686
- })
687
-
688
- const proxy = sandbox.createObjectProxy({
689
- 'kg.sparql.query': (args) => db.querySelect(args.query),
690
- 'kg.embeddings.search': (args) => embeddings.findSimilar(args.entity, args.k, args.threshold)
691
- })
692
-
693
- // All calls are logged, metered, and capability-checked
694
- const result = await proxy['kg.sparql.query']({ query: 'SELECT ?x WHERE { ?x a :Fraud }' })
695
- ```
696
-
697
- **Memory Layer**: Context management across agent lifecycle
698
- ```javascript
699
- const agent = new AgentBuilder('investigator')
700
- .withMemory({
701
- working: { maxSize: 1024 * 1024 }, // 1MB working memory
702
- episodic: { retentionDays: 30 }, // 30-day execution history
703
- longTerm: db // Knowledge graph as long-term memory
704
- })
705
- ```
706
-
707
- **Scope Layer**: Resource isolation and boundaries
708
- ```javascript
709
- const agent = new AgentBuilder('scoped-agent')
710
- .withScope({
711
- namespace: 'fraud-detection',
712
- resourceLimits: {
713
- maxTriples: 1000000,
714
- maxEmbeddings: 100000,
715
- maxConcurrentQueries: 10
716
- }
717
- })
718
- ```
719
-
720
- ---
721
-
722
- ## Feature Overview
723
-
724
- | Category | Feature | What It Does |
725
- |----------|---------|--------------|
726
- | **Core** | GraphDB | High-performance RDF/SPARQL quad store |
727
- | **Core** | SPOC Indexes | Four-way indexing (SPOC/POCS/OCSP/CSPO) |
728
- | **Core** | Dictionary | String interning with 8-byte IDs |
729
- | **Analytics** | GraphFrames | PageRank, connected components, triangles |
730
- | **Analytics** | Motif Finding | Pattern matching DSL |
731
- | **Analytics** | Pregel | BSP parallel graph processing |
732
- | **AI** | Embeddings | HNSW similarity with 1-hop ARCADE cache |
733
- | **AI** | HyperMind | Neuro-symbolic agent framework |
734
- | **Reasoning** | Datalog | Semi-naive evaluation engine |
735
- | **Reasoning** | RDFS Reasoner | Subclass/subproperty inference |
736
- | **Reasoning** | OWL 2 RL | Rule-based OWL reasoning |
737
- | **Ontology** | SHACL | W3C shapes constraint validation |
738
- | **Joins** | WCOJ | Worst-case optimal join algorithm |
739
- | **Distribution** | HDRF | Streaming graph partitioning |
740
- | **Distribution** | Raft | Consensus for coordination |
741
- | **Mobile** | iOS/Android | Swift and Kotlin bindings via UniFFI |
742
- | **Storage** | InMemory/RocksDB/LMDB | Three backend options |
743
-
744
- ---
745
-
746
- ## Installation
747
-
748
- ```bash
749
- npm install rust-kgdb
750
- ```
751
-
752
- **Platforms**: macOS (Intel/Apple Silicon), Linux (x64/ARM64), Windows (x64)
753
-
754
- ---
755
-
756
- ## Quick Start
757
-
758
- ```javascript
759
- const { GraphDB, GraphFrame, EmbeddingService, DatalogProgram, evaluateDatalog } = require('rust-kgdb')
760
-
761
- // 1. Create knowledge graph
762
- const db = new GraphDB('http://example.org/myapp')
763
-
764
- // 2. Load RDF data (Turtle format)
765
- db.loadTtl(`
766
- @prefix : <http://example.org/> .
767
- :alice :knows :bob .
768
- :bob :knows :charlie .
769
- :charlie :knows :alice .
770
- `, null)
771
-
772
- console.log(`Loaded ${db.countTriples()} triples`)
773
-
774
- // 3. Query with SPARQL
775
- const results = db.querySelect(`
776
- PREFIX : <http://example.org/>
777
- SELECT ?person WHERE { ?person :knows :bob }
778
- `)
779
- console.log('People who know Bob:', results)
780
-
781
- // 4. Graph analytics
782
- const graph = new GraphFrame(
783
- JSON.stringify([{id:'alice'}, {id:'bob'}, {id:'charlie'}]),
784
- JSON.stringify([
785
- {src:'alice', dst:'bob'},
786
- {src:'bob', dst:'charlie'},
787
- {src:'charlie', dst:'alice'}
788
- ])
789
- )
790
- console.log('Triangles:', graph.triangleCount()) // 1
791
- console.log('PageRank:', graph.pageRank(0.15, 20))
792
-
793
- // 5. Semantic similarity
794
- const embeddings = new EmbeddingService()
795
- embeddings.storeVector('alice', new Array(384).fill(0.5))
796
- embeddings.storeVector('bob', new Array(384).fill(0.6))
797
- embeddings.rebuildIndex()
798
- console.log('Similar to alice:', embeddings.findSimilar('alice', 5, 0.3))
799
-
800
- // 6. Datalog reasoning
801
- const datalog = new DatalogProgram()
802
- datalog.addFact(JSON.stringify({predicate:'knows', terms:['alice','bob']}))
803
- datalog.addFact(JSON.stringify({predicate:'knows', terms:['bob','charlie']}))
804
- datalog.addRule(JSON.stringify({
805
- head: {predicate:'connected', terms:['?X','?Z']},
806
- body: [
807
- {predicate:'knows', terms:['?X','?Y']},
808
- {predicate:'knows', terms:['?Y','?Z']}
809
- ]
810
- }))
811
- console.log('Inferred:', evaluateDatalog(datalog))
812
- ```
813
-
814
- ---
815
-
816
- ## HyperMind: Where Neural Meets Symbolic
817
-
818
- ```
819
- ╔═══════════════════════════════════════════════╗
820
- ║ THE HYPERMIND ARCHITECTURE ║
821
- ╚═══════════════════════════════════════════════╝
822
-
823
- Natural Language
824
-
825
-
826
- ┌───────────────────────────────────┐
827
- │ LLM (Neural) │
828
- │ "Find circular payment patterns │
829
- │ in claims from last month" │
830
- └───────────────────────────────────┘
831
-
832
-
833
- ┌───────────────────────────────────────────────────────────────────────┐
834
- │ TYPE THEORY LAYER │
835
- │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
836
- │ │ TypeId System │ │ Refinement │ │ Session Types │ │
837
- │ │ (compile-time) │ │ Types │ │ (protocols) │ │
838
- │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
839
- │ ERRORS CAUGHT HERE, NOT RUNTIME │
840
- └───────────────────────────────────────────────────────────────────────┘
841
-
842
-
843
- ┌───────────────────────────────────────────────────────────────────────┐
844
- │ CATEGORY THEORY LAYER │
845
- │ │
846
- │ kg.sparql.query ────► kg.motif.find ────► kg.datalog │
847
- │ (Query → Bindings) (Pattern → Matches) (Rules → Facts) │
848
- │ │
849
- │ f: A → B g: B → C h: C → D │
850
- │ g ∘ f: A → C (COMPOSITION IS TYPE-SAFE) │
851
- └───────────────────────────────────────────────────────────────────────┘
852
-
853
-
854
- ┌───────────────────────────────────────────────────────────────────────┐
855
- │ WASM SANDBOX LAYER │
856
- │ ┌─────────────────────────────────────────────────────────────────┐ │
857
- │ │ wasmtime isolation │ │
858
- │ │ • Isolated linear memory (no host access) │ │
859
- │ │ • CPU fuel metering (10M ops max) │ │
860
- │ │ • Capability-based security │ │
861
- │ │ • NO filesystem, NO network │ │
862
- │ └─────────────────────────────────────────────────────────────────┘ │
863
- └───────────────────────────────────────────────────────────────────────┘
864
-
865
-
866
- ┌───────────────────────────────────────────────────────────────────────┐
867
- │ PROOF THEORY LAYER │
868
- │ │
869
- │ Every execution produces an ExecutionWitness: │
870
- │ { tool, input, output, hash, timestamp, duration } │
871
- │ │
872
- │ Curry-Howard: Types ↔ Propositions, Programs ↔ Proofs │
873
- │ Result: Full audit trail for SOX/GDPR/FDA compliance │
874
- └───────────────────────────────────────────────────────────────────────┘
875
-
876
-
877
- ┌───────────────────────────────────┐
878
- │ Knowledge Graph Result │
879
- │ 15 fraud patterns detected │
880
- │ with complete audit trail │
881
- └───────────────────────────────────┘
882
- ```
883
-
884
- ---
885
-
886
- ## HyperMind Architecture Deep Dive
887
-
888
- For a complete walkthrough of the architecture, run:
889
- ```bash
890
- node examples/hypermind-agent-architecture.js
891
- ```
892
-
893
- ### Full System Architecture
894
-
895
- ```
896
- ╔════════════════════════════════════════════════════════════════════════════════╗
897
- ║ HYPERMIND NEURO-SYMBOLIC ARCHITECTURE ║
898
- ╠════════════════════════════════════════════════════════════════════════════════╣
899
- ║ ║
900
- ║ ┌────────────────────────────────────────────────────────────────────────┐ ║
901
- ║ │ APPLICATION LAYER │ ║
902
- ║ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ ║
903
- ║ │ │ Fraud │ │ Underwriting│ │ Compliance │ │ Custom │ │ ║
904
- ║ │ │ Detection │ │ Agent │ │ Checker │ │ Agents │ │ ║
905
- ║ │ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │ ║
906
- ║ └─────────┼────────────────┼────────────────┼────────────────┼───────────┘ ║
907
- ║ └────────────────┴────────┬───────┴────────────────┘ ║
908
- ║ │ ║
909
- ║ ┌───────────────────────────────────┼────────────────────────────────────┐ ║
910
- ║ │ HYPERMIND RUNTIME │ ║
911
- ║ │ ┌────────────────┐ ┌─────────┴─────────┐ ┌─────────────────┐ │ ║
912
- ║ │ │ LLM PLANNER │ │ PLAN EXECUTOR │ │ WASM SANDBOX │ │ ║
913
- ║ │ │ • Claude/GPT │───▶│ • Type validation │───▶│ • Capabilities │ │ ║
914
- ║ │ │ • Intent parse │ │ • Morphism compose│ │ • Fuel metering │ │ ║
915
- ║ │ │ • Tool select │ │ • Step execution │ │ • Memory limits │ │ ║
916
- ║ │ └────────────────┘ └───────────────────┘ └────────┬────────┘ │ ║
917
- ║ │ │ │ ║
918
- ║ │ ┌───────────────────────────────────────────────────────┼───────────┐ │ ║
919
- ║ │ │ OBJECT PROXY (gRPC-style) │ │ │ ║
920
- ║ │ │ proxy.call("kg.sparql.query", args) ────────────────┤ │ │ ║
921
- ║ │ │ proxy.call("kg.motif.find", args) ────────────────┤ │ │ ║
922
- ║ │ │ proxy.call("kg.datalog.infer", args) ────────────────┤ │ │ ║
923
- ║ │ └───────────────────────────────────────────────────────┼───────────┘ │ ║
924
- ║ └──────────────────────────────────────────────────────────┼─────────────┘ ║
925
- ║ │ ║
926
- ║ ┌──────────────────────────────────────────────────────────┼─────────────┐ ║
927
- ║ │ HYPERMIND TOOLS │ │ ║
928
- ║ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌───┴─────────┐ │ ║
929
- ║ │ │ SPARQL │ │ MOTIF │ │ DATALOG │ │ EMBEDDINGS │ │ ║
930
- ║ │ │ String → │ │ Pattern → │ │ Rules → │ │ Entity → │ │ ║
931
- ║ │ │ BindingSet │ │ List<Match> │ │ List<Fact> │ │ List<Sim> │ │ ║
932
- ║ │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │ ║
933
- ║ └────────────────────────────────────────────────────────────────────────┘ ║
934
- ║ ║
935
- ║ ┌────────────────────────────────────────────────────────────────────────┐ ║
936
- ║ │ rust-kgdb KNOWLEDGE GRAPH │ ║
937
- ║ │ RDF Triples | SPARQL 1.1 | GraphFrames | Embeddings | Datalog │ ║
938
- ║ │ 2.78µs lookups | 24 bytes/triple | 35x faster than RDFox │ ║
939
- ║ └────────────────────────────────────────────────────────────────────────┘ ║
940
- ╚════════════════════════════════════════════════════════════════════════════════╝
941
- ```
942
-
943
- ### Agent Execution Sequence
944
-
945
- ```
946
- ╔════════════════════════════════════════════════════════════════════════════════╗
947
- ║ HYPERMIND AGENT EXECUTION - SEQUENCE DIAGRAM ║
948
- ╠════════════════════════════════════════════════════════════════════════════════╣
949
- ║ ║
950
- ║ User SDK Planner Sandbox Proxy KG ║
951
- ║ │ │ │ │ │ │ ║
952
- ║ │ "Find suspicious claims" │ │ │ │ ║
953
- ║ │────────────▶│ │ │ │ │ ║
954
- ║ │ │ plan(prompt) │ │ │ │ ║
955
- ║ │ │─────────────▶│ │ │ │ ║
956
- ║ │ │ │ ┌──────────────────────────┐│ │ ║
957
- ║ │ │ │ │ LLM Reasoning: ││ │ ║
958
- ║ │ │ │ │ 1. Parse intent ││ │ ║
959
- ║ │ │ │ │ 2. Select tools ││ │ ║
960
- ║ │ │ │ │ 3. Validate types ││ │ ║
961
- ║ │ │ │ └──────────────────────────┘│ │ ║
962
- ║ │ │ Plan{steps, confidence} │ │ │ ║
963
- ║ │ │◀─────────────│ │ │ │ ║
964
- ║ │ │ execute(plan)│ │ │ │ ║
965
- ║ │ │─────────────────────────────▶ │ │ ║
966
- ║ │ │ │ ┌────────────────────────┐ │ │ ║
967
- ║ │ │ │ │ Sandbox Init: │ │ │ ║
968
- ║ │ │ │ │ • Capabilities: [Read] │ │ │ ║
969
- ║ │ │ │ │ • Fuel: 1,000,000 │ │ │ ║
970
- ║ │ │ │ └────────────────────────┘ │ │ ║
971
- ║ │ │ │ │ kg.sparql │ │ ║
972
- ║ │ │ │ │─────────────▶│───────────▶│ ║
973
- ║ │ │ │ │ │ BindingSet │ ║
974
- ║ │ │ │ │◀─────────────│◀───────────│ ║
975
- ║ │ │ │ │ kg.datalog │ │ ║
976
- ║ │ │ │ │─────────────▶│───────────▶│ ║
977
- ║ │ │ │ │ │ List<Fact> │ ║
978
- ║ │ │ │ │◀─────────────│◀───────────│ ║
979
- ║ │ │ ExecutionResult{findings, witness} │ │ ║
980
- ║ │ │◀───────────────────────────── │ │ ║
981
- ║ │ "Found 2 collusion patterns. Evidence: ..." │ │ ║
982
- ║ │◀────────────│ │ │ │ │ ║
983
- ╚════════════════════════════════════════════════════════════════════════════════╝
984
- ```
985
-
986
- ### Architecture Components (v0.5.8+)
987
-
988
- The TypeScript SDK exports production-ready HyperMind components. All execution flows through the **WASM sandbox** for complete security isolation:
989
-
990
- ```javascript
991
- const {
992
- // Type System (Hindley-Milner style)
993
- TypeId, // Base types + refinement types (RiskScore, PolicyNumber)
994
- TOOL_REGISTRY, // Tools as typed morphisms (category theory)
995
-
996
- // Runtime Components
997
- LLMPlanner, // Natural language → typed tool pipelines
998
- WasmSandbox, // Secure WASM isolation with capability-based security
999
- AgentBuilder, // Fluent builder for agent composition
1000
- ComposedAgent, // Executable agent with execution witness
1001
- } = require('rust-kgdb/hypermind-agent')
1002
- ```
1003
-
1004
- **Example: Build a Custom Agent**
1005
- ```javascript
1006
- const { AgentBuilder, LLMPlanner, TypeId, TOOL_REGISTRY } = require('rust-kgdb/hypermind-agent')
1007
-
1008
- // Compose an agent using the builder pattern
1009
- const agent = new AgentBuilder('compliance-checker')
1010
- .withTool('kg.sparql.query')
1011
- .withTool('kg.datalog.infer')
1012
- .withPlanner(new LLMPlanner('claude-sonnet-4', TOOL_REGISTRY))
1013
- .withSandbox({
1014
- capabilities: ['ReadKG', 'ExecuteTool'], // No WriteKG for safety
1015
- fuelLimit: 1000000,
1016
- maxMemory: 64 * 1024 * 1024 // 64MB
1017
- })
1018
- .withHook('afterExecute', (step, result) => {
1019
- console.log(`Completed: ${step.tool} → ${result.length} results`)
1020
- })
1021
- .build()
1022
-
1023
- // Execute with natural language
1024
- const result = await agent.call("Check compliance status for all vendors")
1025
- console.log(result.witness.proof_hash) // sha256:...
1026
- ```
1027
-
1028
- ---
1029
-
1030
- ## HyperMind vs MCP (Model Context Protocol)
1031
-
1032
- Why domain-enriched proxies beat generic function calling:
1033
-
1034
- ```
1035
- ┌───────────────────────┬──────────────────────┬──────────────────────────┐
1036
- │ Feature │ MCP │ HyperMind Proxy │
1037
- ├───────────────────────┼──────────────────────┼──────────────────────────┤
1038
- │ Type Safety │ ❌ String only │ ✅ Full type system │
1039
- │ Domain Knowledge │ ❌ Generic │ ✅ Domain-enriched │
1040
- │ Tool Composition │ ❌ Isolated │ ✅ Morphism composition │
1041
- │ Validation │ ❌ Runtime │ ✅ Compile-time │
1042
- │ Security │ ❌ None │ ✅ WASM sandbox │
1043
- │ Audit Trail │ ❌ None │ ✅ Execution witness │
1044
- │ LLM Context │ ❌ Generic schema │ ✅ Rich domain hints │
1045
- │ Capability Control │ ❌ All or nothing │ ✅ Fine-grained caps │
1046
- ├───────────────────────┼──────────────────────┼──────────────────────────┤
1047
- │ Result │ 60% accuracy │ 95%+ accuracy │
1048
- │ │ "I think this might │ "Rule R1 matched facts │
1049
- │ │ be suspicious..." │ F1,F2,F3. Proof: ..." │
1050
- └───────────────────────┴──────────────────────┴──────────────────────────┘
1051
- ```
1052
-
1053
- ### The Key Insight
1054
-
1055
- **MCP**: LLM generates query → hope it works
1056
- **HyperMind**: LLM selects tools → type system validates → guaranteed correct
1057
-
1058
- ```javascript
1059
- // MCP APPROACH (Generic function calling)
1060
- // Tool: search_database(query: string)
1061
- // LLM generates: "SELECT * FROM claims WHERE suspicious = true"
1062
- // Result: ❌ SQL injection risk, "suspicious" column doesn't exist
1063
-
1064
- // HYPERMIND APPROACH (Domain-enriched proxy)
1065
- // Tool: kg.datalog.infer with NICB fraud rules
1066
- const proxy = sandbox.createObjectProxy(tools)
1067
- const result = await proxy['kg.datalog.infer']({
1068
- rules: ['potential_collusion', 'staged_accident']
1069
- })
1070
- // Result: ✅ Type-safe, domain-aware, auditable
1071
- ```
1072
-
1073
- **Why Domain Proxies Win:**
1074
- 1. LLM becomes **orchestrator**, not executor
1075
- 2. Domain knowledge **reduces hallucination**
1076
- 3. Composition **multiplies capability**
1077
- 4. Audit trail **enables compliance**
1078
- 5. Security **enables enterprise deployment**
1079
-
1080
- ---
1081
-
1082
- ## Why Vanilla LLMs Fail
1083
-
1084
- When you ask an LLM to query a knowledge graph, it produces **broken SPARQL 85% of the time**:
1085
-
1086
- ```
1087
- User: "Find all professors"
1088
-
1089
- Vanilla LLM Output:
1090
- ┌───────────────────────────────────────────────────────────────────────┐
1091
- │ ```sparql │
1092
- │ PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> │
1093
- │ SELECT ?professor WHERE { │
1094
- │ ?professor a ub:Faculty . ← WRONG! Schema has "Professor" │
1095
- │ } │
1096
- │ ``` ← Parser rejects markdown │
1097
- │ │
1098
- │ This query retrieves all faculty members from the LUBM dataset. │
1099
- │ ↑ Explanation text breaks parsing │
1100
- └───────────────────────────────────────────────────────────────────────┘
1101
- Result: ❌ PARSER ERROR - Invalid SPARQL syntax
1102
- ```
1103
-
1104
- **Why it fails:**
1105
- 1. LLM wraps query in markdown code blocks → parser chokes
1106
- 2. LLM adds explanation text → mixed with query syntax
1107
- 3. LLM hallucinates class names → `ub:Faculty` doesn't exist (it's `ub:Professor`)
1108
- 4. LLM has no schema awareness → guesses predicates and classes
1109
-
1110
- ---
1111
-
1112
- ## How HyperMind Solves This
1113
-
1114
- ```
1115
- User: "Find all professors"
1116
-
1117
- HyperMind Output:
1118
- ┌───────────────────────────────────────────────────────────────────────┐
1119
- │ PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> │
1120
- │ SELECT ?professor WHERE { │
1121
- │ ?professor a ub:Professor . ← CORRECT! Schema-aware │
1122
- │ } │
1123
- └───────────────────────────────────────────────────────────────────────┘
1124
- Result: ✅ 15 results returned in 2.3ms
1125
- ```
1126
-
1127
- **Why it works:**
1128
- 1. **Type-checked tools** - Query must be valid SPARQL (compile-time check)
1129
- 2. **Schema integration** - Tools know the ontology, not just the LLM
1130
- 3. **No text pollution** - Query output is typed `SPARQLQuery`, not `string`
1131
- 4. **Deterministic execution** - Same query, same result, always
1132
-
1133
- **Accuracy improvement: 0% → 86.4%** (+86 percentage points on LUBM benchmark)
1134
-
1135
- ---
1136
-
1137
- ## HyperMind in Action: Complete Agent Conversation
1138
-
1139
- This is what a real HyperMind agent interaction looks like. Run `node examples/hypermind-complete-demo.js` to see it yourself.
1140
-
1141
- ```
1142
- ================================================================================
1143
- THE PROBLEM WITH AI AGENTS TODAY
1144
- ================================================================================
1145
-
1146
- You ask ChatGPT: "Find suspicious insurance claims in our data"
1147
- It replies: "Based on typical fraud patterns, you should look for..."
1148
-
1149
- But wait -- it never SAW your data. It's guessing. Hallucinating.
1150
-
1151
- HYPERMIND'S INSIGHT: Use LLMs for UNDERSTANDING, symbolic systems for REASONING.
1152
-
1153
- ================================================================================
1154
-
1155
- +------------------------------------------------------------------------+
1156
- | SECTION 4: DATALOG REASONING |
1157
- | Rule-Based Inference Using NICB Fraud Detection Guidelines |
1158
- +------------------------------------------------------------------------+
1159
-
1160
- RULE 1: potential_collusion(?X, ?Y, ?P)
1161
- IF claimant(?X) AND claimant(?Y) AND provider(?P)
1162
- AND claims_with(?X, ?P) AND claims_with(?Y, ?P)
1163
- AND knows(?X, ?Y)
1164
- THEN potential_collusion(?X, ?Y, ?P)
1165
- Source: NICB Ring Detection Guidelines
1166
-
1167
- Running Datalog Inference Engine...
1168
-
1169
- INFERRED FACTS:
1170
- ---------------
1171
- [!] COLLUSION DETECTED: 1 pattern(s)
1172
- P001 <-> P002 via PROV001
1173
- [!] STAGED ACCIDENT INDICATORS: 3 pattern(s)
1174
- P001 via PROV001
1175
- P002 via PROV001
1176
- P005 via PROV001
1177
-
1178
- +------------------------------------------------------------------------+
1179
- | SECTION 5: HYPERMIND AGENT INTERACTION |
1180
- | Natural Language Interface - The Power of Neuro-Symbolic AI |
1181
- +------------------------------------------------------------------------+
1182
-
1183
- ========================================================================
1184
- USER PROMPT: "Which claims look suspicious and why should I investigate them?"
1185
- ========================================================================
1186
-
1187
- Agent Reasoning:
1188
- 1. Decomposing query: "suspicious claims" -> need risk indicators
1189
- 2. Selecting tools: GraphFrame (network), Embeddings (similarity), Datalog (rules)
1190
- 3. Type checking: All tools compatible (Graph -> Analysis -> Inference)
1191
- 4. Executing pipeline...
1192
-
1193
- ========================================================================
1194
- AGENT RESPONSE:
1195
- ========================================================================
1196
-
1197
- I analyzed 5 claims across 3 providers and found 2 CRITICAL fraud indicators:
1198
-
1199
- [CRITICAL] FINDING 1: COLLUSION RING (Confidence: 95%)
1200
- --------------------------------------------------------
1201
- Claimants: John Smith (P001) + Jane Doe (P002)
1202
- Provider: Quick Care Rehabilitation Clinic
1203
- Evidence:
1204
- - Both filed soft tissue claims within 3 days of each other
1205
- - Both live at 123 Main St (shared address)
1206
- - Both have elevated risk scores (0.85, 0.72)
1207
-
1208
- Rule Triggered: NICB Collusion Pattern
1209
- potential_collusion(P001, P002, PROV001) <- knows AND same_provider AND same_address
1210
-
1211
- Recommendation: IMMEDIATE SIU REFERRAL
1212
-
1213
- EXECUTION WITNESS (Proof Theory - Audit Trail):
1214
- ------------------------------------------------
1215
- Timestamp: 2024-12-14T23:15:00Z
1216
- Agent: fraud-investigator
1217
- Tools:
1218
- - kg.graphframe.triangles: 1 triangle detected
1219
- - kg.embeddings.search: 3 clusters found
1220
- - kg.datalog.infer: 3 fraud patterns derived
1221
- Proof Hash: sha256:a3f2b8c9d1e4...
1222
-
1223
- ========================================================================
1224
- USER FOLLOW-UP: "Show me the rule that detected the collusion"
1225
- ========================================================================
1226
-
1227
- Agent Response:
1228
-
1229
- The collusion was detected by this NICB-derived Datalog rule:
1230
-
1231
- +----------------------------------------------------------------------+
1232
- | RULE: potential_collusion(?X, ?Y, ?P) |
1233
- | |
1234
- | IF: |
1235
- | claimant(?X) <- John Smith is a claimant |
1236
- | claimant(?Y) <- Jane Doe is a claimant |
1237
- | provider(?P) <- Quick Care is a provider |
1238
- | claims_with(?X, ?P) <- John filed claim with Quick Care |
1239
- | claims_with(?Y, ?P) <- Jane filed claim with Quick Care |
1240
- | knows(?X, ?Y) <- John and Jane know each other |
1241
- | |
1242
- | THEN: |
1243
- | potential_collusion(P001, P002, PROV001) |
1244
- | |
1245
- | CONFIDENCE: 100% (all facts verified in knowledge graph) |
1246
- +----------------------------------------------------------------------+
1247
-
1248
- This derivation is 100% deterministic and auditable.
1249
- A regulator can verify this finding by checking the rule against the facts.
1250
- ```
1251
-
1252
- **The Key Difference:**
1253
- - **Vanilla LLM**: "Some claims may be suspicious" (no data access, no proof)
1254
- - **HyperMind**: Specific findings + rule derivations + cryptographic audit trail
1255
-
1256
- **Try it yourself:**
1257
- ```bash
1258
- node examples/hypermind-complete-demo.js # Full 7-section demo
1259
- node examples/fraud-detection-agent.js # Fraud detection pipeline
1260
- node examples/underwriting-agent.js # Underwriting pipeline
1261
- ```
1262
-
1263
- ---
1264
-
1265
- ## Mathematical Foundations
1266
-
1267
- We don't "vibe code" AI agents. Every tool is a **mathematical morphism** with provable properties.
1268
-
1269
- ### Type Theory: Compile-Time Validation
1270
-
1271
- ```typescript
1272
- // Refinement types catch errors BEFORE execution
1273
- type RiskScore = number & { __refinement: '0 ≤ x ≤ 1' }
1274
- type PolicyNumber = string & { __refinement: '/^POL-\\d{9}$/' }
1275
- type CreditScore = number & { __refinement: '300 ≤ x ≤ 850' }
1276
-
1277
- // Framework validates at construction, not runtime
1278
- function assessRisk(score: RiskScore): Decision {
1279
- // score is GUARANTEED to be 0.0-1.0
1280
- // No defensive coding needed
1281
- }
1282
- ```
1283
-
1284
- ### Category Theory: Safe Tool Composition
1285
-
1286
- ```
1287
- Tools are morphisms (typed arrows):
1288
-
1289
- kg.sparql.query: Query → BindingSet
1290
- kg.motif.find: Pattern → Matches
1291
- kg.datalog.apply: Rules → InferredFacts
1292
- kg.embeddings.search: Entity → SimilarEntities
1293
-
1294
- Composition is type-checked:
1295
-
1296
- f: A → B
1297
- g: B → C
1298
- g ∘ f: A → C (valid only if types align)
1299
-
1300
- Laws guaranteed:
1301
- 1. Identity: id ∘ f = f = f ∘ id
1302
- 2. Associativity: (h ∘ g) ∘ f = h ∘ (g ∘ f)
1303
- ```
1304
-
1305
- ### Proof Theory: Auditable Execution
1306
-
1307
- Every execution produces an **ExecutionWitness** (Curry-Howard correspondence):
1308
-
1309
- ```json
1310
- {
1311
- "tool": "kg.sparql.query",
1312
- "input": "SELECT ?x WHERE { ?x a :Fraud }",
1313
- "output": "[{x: 'entity001'}]",
1314
- "inputType": "Query",
1315
- "outputType": "BindingSet",
1316
- "timestamp": "2024-12-14T10:30:00Z",
1317
- "durationMs": 12,
1318
- "hash": "sha256:a3f2c8d9..."
1319
- }
1320
- ```
1321
-
1322
- **Implication**: Full audit trail for SOX, GDPR, FDA 21 CFR Part 11 compliance.
1323
-
1324
- ---
1325
-
1326
- ## Ontology Engine
1327
-
1328
- rust-kgdb includes a complete ontology engine based on W3C standards.
1329
-
1330
- ### RDFS Reasoning
1331
-
1332
- ```turtle
1333
- # Schema
1334
- :Employee rdfs:subClassOf :Person .
1335
- :Manager rdfs:subClassOf :Employee .
1336
-
1337
- # Data
1338
- :alice a :Manager .
1339
-
1340
- # Inferred (automatic)
1341
- :alice a :Employee . # via subclass chain
1342
- :alice a :Person . # via subclass chain
1343
- ```
1344
-
1345
- ### OWL 2 RL Rules
1346
-
1347
- | Rule | Description |
1348
- |------|-------------|
1349
- | `prp-dom` | Property domain inference |
1350
- | `prp-rng` | Property range inference |
1351
- | `prp-symp` | Symmetric property |
1352
- | `prp-trp` | Transitive property |
1353
- | `cls-hv` | hasValue restriction |
1354
- | `cls-svf` | someValuesFrom restriction |
1355
- | `cax-sco` | Subclass transitivity |
1356
-
1357
- ### SHACL Validation
1358
-
1359
- ```turtle
1360
- :PersonShape a sh:NodeShape ;
1361
- sh:targetClass :Person ;
1362
- sh:property [
1363
- sh:path :email ;
1364
- sh:pattern "^[a-z]+@[a-z]+\\.[a-z]+$" ;
1365
- sh:minCount 1 ;
1366
- ] .
1367
- ```
1368
-
1369
- ---
1370
-
1371
- ## Production Example: Fraud Detection
1372
-
1373
- **Data Sources:** Example patterns based on [NICB (National Insurance Crime Bureau)](https://www.nicb.org/) published fraud statistics:
1374
- - Staged accidents: 20% of insurance fraud
1375
- - Provider collusion: 25% of fraud claims
1376
- - Ring operations: 40% of organized fraud
1377
-
1378
- **Pattern Recognition:** Circular payment detection mirrors real SIU (Special Investigation Unit) methodologies from major insurers.
1379
-
1380
- ### Pre-Steps: Dataset and Embedding Configuration
1381
-
1382
- Before running the fraud detection pipeline, configure your environment:
1383
-
1384
- ```javascript
1385
- // ============================================================
1386
- // STEP 1: Environment Configuration
1387
- // ============================================================
1388
- const { GraphDB, GraphFrame, EmbeddingService, DatalogProgram, evaluateDatalog } = require('rust-kgdb')
1389
- const { AgentBuilder, LLMPlanner, WasmSandbox, TOOL_REGISTRY } = require('rust-kgdb/hypermind-agent')
1390
-
1391
- // Configure embedding provider (choose one)
1392
- const EMBEDDING_PROVIDER = process.env.EMBEDDING_PROVIDER || 'mock'
1393
- const OPENAI_API_KEY = process.env.OPENAI_API_KEY
1394
- const VOYAGE_API_KEY = process.env.VOYAGE_API_KEY
1395
-
1396
- // Embedding dimension must match provider output
1397
- const EMBEDDING_DIM = 384
1398
-
1399
- // ============================================================
1400
- // STEP 2: Initialize Services
1401
- // ============================================================
1402
- const db = new GraphDB('http://insurance.org/fraud-kb')
1403
- const embeddings = new EmbeddingService()
1404
-
1405
- // ============================================================
1406
- // STEP 3: Configure Embedding Provider (bring your own)
1407
- // ============================================================
1408
- async function getEmbedding(text) {
1409
- switch (EMBEDDING_PROVIDER) {
1410
- case 'openai':
1411
- // Requires: npm install openai
1412
- const { OpenAI } = require('openai')
1413
- const openai = new OpenAI({ apiKey: OPENAI_API_KEY })
1414
- const resp = await openai.embeddings.create({
1415
- model: 'text-embedding-3-small',
1416
- input: text,
1417
- dimensions: EMBEDDING_DIM
1418
- })
1419
- return resp.data[0].embedding
1420
-
1421
- case 'voyage':
1422
- // Using fetch directly (no SDK required)
1423
- const vResp = await fetch('https://api.voyageai.com/v1/embeddings', {
1424
- method: 'POST',
1425
- headers: {
1426
- 'Authorization': `Bearer ${VOYAGE_API_KEY}`,
1427
- 'Content-Type': 'application/json'
1428
- },
1429
- body: JSON.stringify({ input: text, model: 'voyage-2' })
1430
- })
1431
- const vData = await vResp.json()
1432
- return vData.data[0].embedding.slice(0, EMBEDDING_DIM)
1433
-
1434
- default: // Mock embeddings for testing (no external deps)
1435
- return new Array(EMBEDDING_DIM).fill(0).map((_, i) =>
1436
- Math.sin(text.charCodeAt(i % text.length) * 0.1) * 0.5 + 0.5
1437
- )
1438
- }
1439
- }
1440
-
1441
- // ============================================================
1442
- // STEP 4: Load Dataset with Embedding Triggers
1443
- // ============================================================
1444
- async function loadClaimsDataset() {
1445
- // Load structured RDF data
1446
- db.loadTtl(`
1447
- @prefix : <http://insurance.org/> .
1448
- @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
1449
-
1450
- # Claims
1451
- :CLM001 a :Claim ;
1452
- :amount "18500"^^xsd:decimal ;
1453
- :description "Soft tissue injury from rear-end collision" ;
1454
- :claimant :P001 ;
1455
- :provider :PROV001 ;
1456
- :filingDate "2024-11-15"^^xsd:date .
1457
-
1458
- :CLM002 a :Claim ;
1459
- :amount "22300"^^xsd:decimal ;
1460
- :description "Whiplash injury from vehicle accident" ;
1461
- :claimant :P002 ;
1462
- :provider :PROV001 ;
1463
- :filingDate "2024-11-18"^^xsd:date .
1464
-
1465
- # Claimants
1466
- :P001 a :Claimant ;
1467
- :name "John Smith" ;
1468
- :address "123 Main St, Miami, FL" ;
1469
- :riskScore "0.85"^^xsd:decimal .
1470
-
1471
- :P002 a :Claimant ;
1472
- :name "Jane Doe" ;
1473
- :address "123 Main St, Miami, FL" ; # Same address!
1474
- :riskScore "0.72"^^xsd:decimal .
1475
-
1476
- # Relationships (fraud indicators)
1477
- :P001 :knows :P002 .
1478
- :P001 :paidTo :P002 .
1479
- :P002 :paidTo :P003 .
1480
- :P003 :paidTo :P001 . # Circular payment!
1481
-
1482
- # Provider
1483
- :PROV001 a :Provider ;
1484
- :name "Quick Care Rehabilitation Clinic" ;
1485
- :flagCount "4"^^xsd:integer .
1486
- `, null)
1487
-
1488
- console.log(`[Dataset] Loaded ${db.countTriples()} triples`)
1489
-
1490
- // Generate embeddings for claims (TRIGGER)
1491
- const claims = ['CLM001', 'CLM002']
1492
- for (const claimId of claims) {
1493
- const desc = db.querySelect(`
1494
- PREFIX : <http://insurance.org/>
1495
- SELECT ?desc WHERE { :${claimId} :description ?desc }
1496
- `)[0]?.bindings?.desc || claimId
1497
-
1498
- const vector = await getEmbedding(desc)
1499
- embeddings.storeVector(claimId, vector)
1500
- console.log(`[Embedding] Stored ${claimId}: ${vector.slice(0, 3).map(v => v.toFixed(3)).join(', ')}...`)
1501
- }
1502
-
1503
- // Update 1-hop cache (TRIGGER)
1504
- embeddings.onTripleInsert('CLM001', 'claimant', 'P001', null)
1505
- embeddings.onTripleInsert('CLM001', 'provider', 'PROV001', null)
1506
- embeddings.onTripleInsert('CLM002', 'claimant', 'P002', null)
1507
- embeddings.onTripleInsert('CLM002', 'provider', 'PROV001', null)
1508
- embeddings.onTripleInsert('P001', 'knows', 'P002', null)
1509
- console.log('[1-Hop Cache] Updated neighbor relationships')
1510
-
1511
- // Rebuild HNSW index
1512
- embeddings.rebuildIndex()
1513
- console.log('[HNSW Index] Rebuilt for similarity search')
1514
- }
1515
-
1516
- // ============================================================
1517
- // STEP 5: Run Fraud Detection Pipeline
1518
- // ============================================================
1519
- async function runFraudDetection() {
1520
- await loadClaimsDataset()
1521
-
1522
- // Graph network analysis
1523
- const graph = new GraphFrame(
1524
- JSON.stringify([{id:'P001'}, {id:'P002'}, {id:'P003'}]),
1525
- JSON.stringify([
1526
- {src:'P001', dst:'P002'},
1527
- {src:'P002', dst:'P003'},
1528
- {src:'P003', dst:'P001'}
1529
- ])
1530
- )
1531
-
1532
- const triangles = graph.triangleCount()
1533
- console.log(`[GraphFrame] Fraud rings detected: ${triangles}`)
1534
-
1535
- // Semantic similarity search
1536
- const similarClaims = JSON.parse(embeddings.findSimilar('CLM001', 5, 0.7))
1537
- console.log(`[Embeddings] Claims similar to CLM001:`, similarClaims)
1538
-
1539
- // Datalog rule-based inference
1540
- const datalog = new DatalogProgram()
1541
- datalog.addFact(JSON.stringify({predicate:'claim', terms:['CLM001','P001','PROV001']}))
1542
- datalog.addFact(JSON.stringify({predicate:'claim', terms:['CLM002','P002','PROV001']}))
1543
- datalog.addFact(JSON.stringify({predicate:'related', terms:['P001','P002']}))
1544
-
1545
- datalog.addRule(JSON.stringify({
1546
- head: {predicate:'collusion', terms:['?P1','?P2','?Prov']},
1547
- body: [
1548
- {predicate:'claim', terms:['?C1','?P1','?Prov']},
1549
- {predicate:'claim', terms:['?C2','?P2','?Prov']},
1550
- {predicate:'related', terms:['?P1','?P2']}
1551
- ]
1552
- }))
1553
-
1554
- const result = JSON.parse(evaluateDatalog(datalog))
1555
- console.log('[Datalog] Collusion detected:', result.collusion)
1556
- // Output: [["P001","P002","PROV001"]]
1557
- }
1558
-
1559
- runFraudDetection()
1560
- ```
1561
-
1562
- **Run it yourself:**
1563
- ```bash
1564
- node examples/fraud-detection-agent.js
1565
- ```
1566
-
1567
- **Actual Output:**
1568
- ```
1569
- ======================================================================
1570
- FRAUD DETECTION AGENT - Production Pipeline
1571
- rust-kgdb v0.2.0 | Neuro-Symbolic AI Framework
1572
- ======================================================================
1573
-
1574
- [PHASE 1] Knowledge Graph Initialization
1575
- --------------------------------------------------
1576
- Graph URI: http://insurance.org/fraud-kb
1577
- Triples: 13
1578
-
1579
- [PHASE 2] Graph Network Analysis
1580
- --------------------------------------------------
1581
- Vertices: 7
1582
- Edges: 8
1583
- Triangles: 1 (fraud ring indicator)
1584
- PageRank (central actors):
1585
- - PROV001: 0.2169
1586
- - P001: 0.1418
1587
-
1588
- [PHASE 3] Semantic Similarity Analysis
1589
- --------------------------------------------------
1590
- Embeddings stored: 5
1591
- Vector dimension: 384
1592
-
1593
- [PHASE 4] Datalog Rule-Based Inference
1594
- --------------------------------------------------
1595
- Facts: 6
1596
- Rules: 2
1597
- Inferred facts:
1598
- - Collusion: [["P001","P002","PROV001"]]
1599
- - Connected: [["P001","P003"]]
1600
-
1601
- ======================================================================
1602
- FRAUD DETECTION REPORT - OVERALL RISK: HIGH
1603
- ======================================================================
1604
- ```
1605
-
1606
- ---
1607
-
1608
- ## Production Example: Underwriting
1609
-
1610
- **Data Sources:** Rating factors based on [ISO (Insurance Services Office)](https://www.verisk.com/insurance/brands/iso/) industry standards:
1611
- - NAICS codes: US Census Bureau industry classification
1612
- - Territory modifiers: Based on catastrophe exposure (hurricane zones FL, earthquake CA)
1613
- - Loss ratio thresholds: Industry standard 0.70 referral trigger
1614
- - Experience modification: Standard 5/10 year breaks
1615
-
1616
- **Premium Formula:** `Base Rate × Exposure × Territory Mod × Experience Mod × Loss Mod` - standard ISO methodology.
1617
-
1618
- ```javascript
1619
- const { GraphDB, GraphFrame, DatalogProgram, evaluateDatalog } = require('rust-kgdb')
1620
-
1621
- // Load risk factors
1622
- const db = new GraphDB('http://underwriting.org/kb')
1623
- db.loadTtl(`
1624
- @prefix : <http://underwriting.org/> .
1625
- :BUS001 :naics "332119" ; :lossRatio "0.45" ; :territory "FL" .
1626
- :BUS002 :naics "541512" ; :lossRatio "0.00" ; :territory "CA" .
1627
- :BUS003 :naics "484121" ; :lossRatio "0.72" ; :territory "TX" .
1628
- `, null)
1629
-
1630
- // Apply underwriting rules
1631
- const datalog = new DatalogProgram()
1632
- datalog.addFact(JSON.stringify({predicate:'business', terms:['BUS001','manufacturing','0.45']}))
1633
- datalog.addFact(JSON.stringify({predicate:'business', terms:['BUS002','tech','0.00']}))
1634
- datalog.addFact(JSON.stringify({predicate:'business', terms:['BUS003','transport','0.72']}))
1635
- datalog.addFact(JSON.stringify({predicate:'highRiskClass', terms:['transport']}))
1636
-
1637
- datalog.addRule(JSON.stringify({
1638
- head: {predicate:'referToUW', terms:['?Bus']},
1639
- body: [
1640
- {predicate:'business', terms:['?Bus','?Class','?LR']},
1641
- {predicate:'highRiskClass', terms:['?Class']}
1642
- ]
1643
- }))
1644
-
1645
- datalog.addRule(JSON.stringify({
1646
- head: {predicate:'autoApprove', terms:['?Bus']},
1647
- body: [{predicate:'business', terms:['?Bus','tech','?LR']}]
1648
- }))
1649
-
1650
- const decisions = JSON.parse(evaluateDatalog(datalog))
1651
- console.log('Auto-approve:', decisions.autoApprove) // [["BUS002"]]
1652
- console.log('Refer to UW:', decisions.referToUW) // [["BUS003"]]
1653
- ```
1654
-
1655
- **Run it yourself:**
1656
- ```bash
1657
- node examples/underwriting-agent.js
1658
- ```
1659
-
1660
- **Actual Output:**
1661
- ```
1662
- ======================================================================
1663
- INSURANCE UNDERWRITING AGENT - Production Pipeline
1664
- rust-kgdb v0.2.0 | Neuro-Symbolic AI Framework
1665
- ======================================================================
1666
-
1667
- [PHASE 2] Risk Factor Analysis
1668
- --------------------------------------------------
1669
- Risk network: 12 nodes, 10 edges
1670
- Risk concentration (PageRank):
1671
- - BUS001: 0.0561
1672
- - BUS003: 0.0561
1673
-
1674
- [PHASE 3] Similar Risk Profile Matching
1675
- --------------------------------------------------
1676
- Risk embeddings stored: 4
1677
- Profiles similar to BUS003 (high-risk transportation):
1678
- - BUS001: manufacturing, loss ratio 0.45
1679
- - BUS004: hospitality, loss ratio 0.28
1680
-
1681
- [PHASE 4] Underwriting Decision Rules
1682
- --------------------------------------------------
1683
- Facts loaded: 6
1684
- Decision rules: 2
1685
- Automated decisions:
1686
- - BUS002: AUTO-APPROVE
1687
- - BUS003: REFER TO UNDERWRITER
1688
-
1689
- [PHASE 5] Premium Calculation
1690
- --------------------------------------------------
1691
- - BUS001: $1,339,537 (STANDARD)
1692
- - BUS002: $74,155 (APPROVED)
1693
- - BUS003: $1,125,778 (REFER)
1694
-
1695
- ======================================================================
1696
- Applications processed: 4 | Auto-approved: 1 | Referred: 1
1697
- ======================================================================
1698
- ```
1699
-
1700
- ---
1701
-
1702
- ## HyperMind Agent Design: A Complete Guide
1703
-
1704
- This section explains how to design production-grade AI agents using HyperMind's mathematical foundations. We'll walk through the complete architecture using our Fraud Detection and Underwriting agents as case studies.
1705
-
1706
- ### The HyperMind Architecture
1707
-
1708
- ```
1709
- ┌─────────────────────────────────────────────────────────────────────────────┐
1710
- │ HYPERMIND FRAMEWORK │
1711
- │ │
1712
- │ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │
1713
- │ │ TYPE THEORY │ │ CATEGORY │ │ PROOF │ │
1714
- │ │ (Hindley- │ │ THEORY │ │ THEORY │ │
1715
- │ │ Milner) │ │ (Morphisms) │ │ (Witnesses) │ │
1716
- │ └───────┬───────┘ └───────┬───────┘ └───────┬───────┘ │
1717
- │ │ │ │ │
1718
- │ └─────────────┬─────┴───────────────────┘ │
1719
- │ │ │
1720
- │ ┌─────────────────────▼─────────────────────────────────────────┐ │
1721
- │ │ TOOL REGISTRY │ │
1722
- │ │ Every tool is a typed morphism: Input Type → Output Type │ │
1723
- │ │ │ │
1724
- │ │ kg.sparql.query : SPARQLQuery → BindingSet │ │
1725
- │ │ kg.graphframe : Graph → AnalysisResult │ │
1726
- │ │ kg.embeddings : EntityId → SimilarEntities │ │
1727
- │ │ kg.datalog : DatalogProgram → InferredFacts │ │
1728
- │ └───────────────────────────────────────────────────────────────┘ │
1729
- │ │ │
1730
- │ ┌─────────────────────▼─────────────────────────────────────────┐ │
1731
- │ │ AGENT EXECUTOR │ │
1732
- │ │ Composes tools safely • Produces execution witness │ │
1733
- │ └───────────────────────────────────────────────────────────────┘ │
1734
- └─────────────────────────────────────────────────────────────────────────────┘
1735
- ```
1736
-
1737
- ### Step 1: Design Your Knowledge Graph
1738
-
1739
- The knowledge graph is the foundation. It encodes domain expertise as structured data.
1740
-
1741
- **Fraud Detection Domain Model:**
1742
- ```
1743
- ┌─────────────┐ paidTo ┌─────────────┐
1744
- │ Claimant │ ───────────────▶│ Claimant │
1745
- │ (P001) │ │ (P002) │
1746
- └──────┬──────┘ └──────┬──────┘
1747
- │ claimant │ claimant
1748
- ▼ ▼
1749
- ┌─────────────┐ ┌─────────────┐
1750
- │ Claim │ provider │ Claim │
1751
- │ (CLM001) │ ───────────────▶│ (CLM002) │
1752
- └──────┬──────┘ ┌─────────┴─────────────┘
1753
- │ │
1754
- ▼ ▼
1755
- ┌──────────────────────┐
1756
- │ Provider │ ◀── High claim volume signals risk
1757
- │ (PROV001) │
1758
- └──────────────────────┘
1759
- ```
1760
-
1761
- **Code: Loading the Graph**
1762
- ```javascript
1763
- const { GraphDB } = require('rust-kgdb')
1764
-
1765
- const db = new GraphDB('http://insurance.org/fraud-kb')
1766
-
1767
- // NICB-informed fraud ontology with real patterns
1768
- db.loadTtl(`
1769
- @prefix ins: <http://insurance.org/> .
1770
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
1771
- @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
1772
-
1773
- # Claimants with risk scores
1774
- ins:P001 rdf:type ins:Claimant ;
1775
- ins:name "John Smith" ;
1776
- ins:riskScore "0.85"^^xsd:float .
1777
-
1778
- ins:P002 rdf:type ins:Claimant ;
1779
- ins:name "Jane Doe" ;
1780
- ins:riskScore "0.72"^^xsd:float .
1781
-
1782
- # Claims linked to claimants and providers
1783
- ins:CLM001 rdf:type ins:Claim ;
1784
- ins:claimant ins:P001 ;
1785
- ins:provider ins:PROV001 ;
1786
- ins:amount "18500"^^xsd:decimal .
1787
-
1788
- # Fraud ring indicator: claimants know each other
1789
- ins:P001 ins:knows ins:P002 .
1790
- ins:P001 ins:sameAddress ins:P002 .
1791
- `, 'http://insurance.org/fraud-kb')
1792
-
1793
- console.log(`Knowledge Graph: ${db.countTriples()} triples`)
1794
- ```
1795
-
1796
- ### Step 2: Graph Analytics with GraphFrames
1797
-
1798
- GraphFrames detect structural patterns that indicate fraud rings.
1799
-
1800
- **Design Thinking:** Fraud rings create network triangles. If A→B→C→A, there's a closed loop of money flow - a classic fraud indicator.
1801
-
1802
- ```
1803
- Triangle Detection: PageRank Analysis:
1804
-
1805
- P001 PROV001: 0.2169 ← Central actor
1806
- ╱ ╲ P001: 0.1418 ← High influence
1807
- ╱ ╲ P002: 0.1312 ← Connected to ring
1808
- ▼ ▼
1809
- P002 ────▶ P003 Interpretation: PROV001 is the hub
1810
- ↖____/ that connects multiple claimants.
1811
-
1812
- 1 Triangle = 1 Fraud Ring
1813
- ```
1814
-
1815
- **Code: Network Analysis**
1816
- ```javascript
1817
- const { GraphFrame } = require('rust-kgdb')
1818
-
1819
- // Model the payment network as a graph
1820
- const vertices = [
1821
- { id: 'P001', type: 'claimant', risk: 0.85 },
1822
- { id: 'P002', type: 'claimant', risk: 0.72 },
1823
- { id: 'P003', type: 'claimant', risk: 0.45 },
1824
- { id: 'PROV001', type: 'provider', claimCount: 847 }
1825
- ]
1826
-
1827
- const edges = [
1828
- { src: 'P001', dst: 'P002', relationship: 'paidTo' },
1829
- { src: 'P002', dst: 'P003', relationship: 'paidTo' },
1830
- { src: 'P003', dst: 'P001', relationship: 'paidTo' }, // Closes the loop!
1831
- { src: 'P001', dst: 'PROV001', relationship: 'claimsWith' },
1832
- { src: 'P002', dst: 'PROV001', relationship: 'claimsWith' }
1833
- ]
1834
-
1835
- // GraphFrame requires JSON strings
1836
- const gf = new GraphFrame(JSON.stringify(vertices), JSON.stringify(edges))
1837
-
1838
- // Detect triangles (fraud rings)
1839
- const triangles = gf.triangleCount()
1840
- console.log(`Fraud rings detected: ${triangles}`) // 1
1841
-
1842
- // Find central actors with PageRank
1843
- const pageRankJson = gf.pageRank(0.85, 20)
1844
- const pageRank = JSON.parse(pageRankJson)
1845
- console.log('Central actors:', pageRank.ranks)
1846
- ```
1847
-
1848
- ### Step 3: Semantic Similarity with Embeddings
1849
-
1850
- Embeddings find claims with similar characteristics - useful for detecting patterns across different fraud schemes.
1851
-
1852
- **Design Thinking:** Claims with similar profiles (same type, similar amounts, same provider type) cluster together in vector space.
1853
-
1854
- ```
1855
- Vector Space Visualization:
1856
-
1857
- High Amount
1858
-
1859
- │ CLM001 (bodily injury, $18.5K)
1860
- │ ●
1861
- │ ╲ similarity: 0.815
1862
- │ ╲
1863
- │ ● CLM002 (bodily injury, $22.3K)
1864
-
1865
- │ ● CLM003 (collision, $15.8K)
1866
- Low Risk ─┼────────────────────────── High Risk
1867
-
1868
- │ ● CLM005 (property, $3.2K)
1869
-
1870
- Low Amount
1871
-
1872
- Claims cluster by type + amount + risk.
1873
- Similar claims = similar fraud patterns.
1874
- ```
1875
-
1876
- **Code: Embedding Storage and Search**
1877
- ```javascript
1878
- const { EmbeddingService } = require('rust-kgdb')
1879
-
1880
- const embeddings = new EmbeddingService()
1881
-
1882
- // Generate embeddings from claim characteristics
1883
- function generateClaimEmbedding(claimType, amount, providerVolume, riskScore) {
1884
- // Create 384-dimensional vector encoding claim profile
1885
- const embedding = new Array(384).fill(0)
1886
-
1887
- // Encode claim type (one-hot style in first dimensions)
1888
- const typeIndex = { 'bodily_injury': 0, 'collision': 1, 'property': 2 }
1889
- embedding[typeIndex[claimType] || 0] = 1.0
1890
-
1891
- // Encode normalized values
1892
- embedding[10] = amount / 50000 // Normalize amount
1893
- embedding[11] = providerVolume / 1000 // Normalize provider volume
1894
- embedding[12] = riskScore // Risk score (0-1)
1895
-
1896
- // Add some variance for realistic embedding
1897
- for (let i = 13; i < 384; i++) {
1898
- embedding[i] = Math.sin(i * amount * 0.001) * 0.1
1899
- }
1900
-
1901
- return embedding
1902
- }
1903
-
1904
- // Store claim embeddings
1905
- const claims = {
1906
- 'CLM001': { type: 'bodily_injury', amount: 18500, volume: 847, risk: 0.85 },
1907
- 'CLM002': { type: 'bodily_injury', amount: 22300, volume: 847, risk: 0.72 },
1908
- 'CLM003': { type: 'collision', amount: 15800, volume: 2341, risk: 0.45 },
1909
- 'CLM004': { type: 'property', amount: 3200, volume: 156, risk: 0.22 }
1910
- }
1911
-
1912
- Object.entries(claims).forEach(([id, profile]) => {
1913
- const vec = generateClaimEmbedding(profile.type, profile.amount, profile.volume, profile.risk)
1914
- embeddings.storeVector(id, vec)
1915
- })
1916
-
1917
- // Find claims similar to high-risk CLM001
1918
- const similarJson = embeddings.findSimilar('CLM001', 5, 0.5)
1919
- const similar = JSON.parse(similarJson)
1920
-
1921
- similar.forEach(s => {
1922
- if (s.entity !== 'CLM001') {
1923
- console.log(`${s.entity}: similarity ${s.score.toFixed(3)}`)
1924
- }
1925
- })
1926
- // CLM002: 0.815 (same type, similar amount)
1927
- // CLM003: 0.679 (different type, but similar profile)
1928
- ```
1929
-
1930
- ### Step 4: Rule-Based Inference with Datalog
1931
-
1932
- Datalog applies logical rules to infer fraud patterns. This is the "expert system" component.
1933
-
1934
- **Design Thinking:** Domain experts encode their knowledge as rules. The engine applies these rules automatically.
1935
-
1936
- ```
1937
- NICB Fraud Detection Rules:
1938
-
1939
- Rule 1: COLLUSION
1940
- IF claimant(X) AND claimant(Y) AND
1941
- provider(P) AND claims_with(X, P) AND
1942
- claims_with(Y, P) AND knows(X, Y)
1943
- THEN potential_collusion(X, Y, P)
1944
-
1945
- Rule 2: ADDRESS FRAUD
1946
- IF claimant(X) AND claimant(Y) AND
1947
- same_address(X, Y) AND high_risk(X) AND high_risk(Y)
1948
- THEN address_fraud_indicator(X, Y)
1949
-
1950
- Inference Chain:
1951
- claimant(P001) ┐
1952
- claimant(P002) │
1953
- provider(PROV001) │──▶ potential_collusion(P001, P002, PROV001)
1954
- claims_with(P001,PROV001)│
1955
- claims_with(P002,PROV001)│
1956
- knows(P001, P002) ┘
1957
- ```
1958
-
1959
- **Code: Datalog Inference**
1960
- ```javascript
1961
- const { DatalogProgram, evaluateDatalog } = require('rust-kgdb')
1962
-
1963
- const datalog = new DatalogProgram()
1964
-
1965
- // Add facts from knowledge graph
1966
- datalog.addFact(JSON.stringify({ predicate: 'claimant', terms: ['P001'] }))
1967
- datalog.addFact(JSON.stringify({ predicate: 'claimant', terms: ['P002'] }))
1968
- datalog.addFact(JSON.stringify({ predicate: 'provider', terms: ['PROV001'] }))
1969
- datalog.addFact(JSON.stringify({ predicate: 'claims_with', terms: ['P001', 'PROV001'] }))
1970
- datalog.addFact(JSON.stringify({ predicate: 'claims_with', terms: ['P002', 'PROV001'] }))
1971
- datalog.addFact(JSON.stringify({ predicate: 'knows', terms: ['P001', 'P002'] }))
1972
- datalog.addFact(JSON.stringify({ predicate: 'same_address', terms: ['P001', 'P002'] }))
1973
- datalog.addFact(JSON.stringify({ predicate: 'high_risk', terms: ['P001'] }))
1974
- datalog.addFact(JSON.stringify({ predicate: 'high_risk', terms: ['P002'] }))
1975
-
1976
- // Add NICB-informed collusion rule
1977
- datalog.addRule(JSON.stringify({
1978
- head: { predicate: 'potential_collusion', terms: ['?X', '?Y', '?P'] },
1979
- body: [
1980
- { predicate: 'claimant', terms: ['?X'] },
1981
- { predicate: 'claimant', terms: ['?Y'] },
1982
- { predicate: 'provider', terms: ['?P'] },
1983
- { predicate: 'claims_with', terms: ['?X', '?P'] },
1984
- { predicate: 'claims_with', terms: ['?Y', '?P'] },
1985
- { predicate: 'knows', terms: ['?X', '?Y'] }
1986
- ]
1987
- }))
1988
-
1989
- // Add address fraud rule
1990
- datalog.addRule(JSON.stringify({
1991
- head: { predicate: 'address_fraud_indicator', terms: ['?X', '?Y'] },
1992
- body: [
1993
- { predicate: 'claimant', terms: ['?X'] },
1994
- { predicate: 'claimant', terms: ['?Y'] },
1995
- { predicate: 'same_address', terms: ['?X', '?Y'] },
1996
- { predicate: 'high_risk', terms: ['?X'] },
1997
- { predicate: 'high_risk', terms: ['?Y'] }
1998
- ]
1999
- }))
2000
-
2001
- // Run inference
2002
- const resultJson = evaluateDatalog(datalog)
2003
- const result = JSON.parse(resultJson)
2004
-
2005
- console.log('Collusion:', result.potential_collusion)
2006
- // [["P001", "P002", "PROV001"]]
2007
-
2008
- console.log('Address Fraud:', result.address_fraud_indicator)
2009
- // [["P001", "P002"]]
2010
- ```
2011
-
2012
- ### Step 5: Compose Into HyperMind Agent
2013
-
2014
- Now we compose all tools into a coherent agent with execution witness.
2015
-
2016
- **Design Thinking:** The agent orchestrates tools as typed morphisms. Each tool has a signature (A → B), and composition is type-safe.
2017
-
2018
- ```
2019
- Agent Execution Flow:
2020
-
2021
- ┌─────────────────────────────────────────────────────────────────┐
2022
- │ HyperMindAgent.spawn() │
2023
- │ │
2024
- │ AgentSpec: { │
2025
- │ name: "fraud-detector", │
2026
- │ model: "claude-sonnet-4", │
2027
- │ tools: [kg.sparql.query, kg.graphframe, kg.embeddings, │
2028
- │ kg.datalog] │
2029
- │ } │
2030
- └─────────────────────┬───────────────────────────────────────────┘
2031
-
2032
-
2033
- ┌─────────────────────────────────────────────────────────────────┐
2034
- │ TOOL 1: kg.sparql.query │
2035
- │ Type: SPARQLQuery → BindingSet │
2036
- │ Input: "SELECT ?claimant WHERE { ?claimant :riskScore ?s . }" │
2037
- │ Output: [{ claimant: "P001" }, { claimant: "P002" }] │
2038
- └─────────────────────┬───────────────────────────────────────────┘
2039
-
2040
-
2041
- ┌─────────────────────────────────────────────────────────────────┐
2042
- │ TOOL 2: kg.graphframe.triangles │
2043
- │ Type: Graph → TriangleCount │
2044
- │ Input: 4 nodes, 5 edges │
2045
- │ Output: 1 triangle (fraud ring indicator) │
2046
- └─────────────────────┬───────────────────────────────────────────┘
2047
-
2048
-
2049
- ┌─────────────────────────────────────────────────────────────────┐
2050
- │ TOOL 3: kg.embeddings.search │
2051
- │ Type: EntityId → List[SimilarEntity] │
2052
- │ Input: "CLM001" │
2053
- │ Output: [{entity:"CLM002", score:0.815}, ...] │
2054
- └─────────────────────┬───────────────────────────────────────────┘
2055
-
2056
-
2057
- ┌─────────────────────────────────────────────────────────────────┐
2058
- │ TOOL 4: kg.datalog.infer │
2059
- │ Type: DatalogProgram → InferredFacts │
2060
- │ Input: 9 facts, 2 rules │
2061
- │ Output: { collusion: [...], address_fraud: [...] } │
2062
- └─────────────────────┬───────────────────────────────────────────┘
2063
-
2064
-
2065
- ┌─────────────────────────────────────────────────────────────────┐
2066
- │ EXECUTION WITNESS │
2067
- │ │
2068
- │ { │
2069
- │ "agent": "fraud-detector", │
2070
- │ "timestamp": "2024-12-14T22:41:34.077Z", │
2071
- │ "tools_executed": 4, │
2072
- │ "findings": { │
2073
- │ "triangles": 1, │
2074
- │ "collusions": 1, │
2075
- │ "addressFraud": 1 │
2076
- │ }, │
2077
- │ "proof_hash": "sha256:000000005330d147" │
2078
- │ } │
2079
- └─────────────────────────────────────────────────────────────────┘
2080
- ```
2081
-
2082
- **Complete Agent Code:**
2083
- ```javascript
2084
- const { HyperMindAgent } = require('rust-kgdb/hypermind-agent')
2085
- const { GraphDB, GraphFrame, EmbeddingService, DatalogProgram, evaluateDatalog } = require('rust-kgdb')
2086
-
2087
- async function runFraudDetectionAgent() {
2088
- // Step 1: Initialize Knowledge Graph
2089
- const db = new GraphDB('http://insurance.org/fraud-kb')
2090
- db.loadTtl(FRAUD_ONTOLOGY, 'http://insurance.org/fraud-kb')
2091
-
2092
- // Step 2: Spawn Agent
2093
- const agent = await HyperMindAgent.spawn({
2094
- name: 'fraud-detector',
2095
- model: process.env.ANTHROPIC_API_KEY ? 'claude-sonnet-4' : 'mock',
2096
- tools: ['kg.sparql.query', 'kg.graphframe', 'kg.embeddings.search', 'kg.datalog.apply'],
2097
- tracing: true
2098
- })
2099
-
2100
- // Step 3: Execute Tool Pipeline
2101
- const findings = {}
2102
-
2103
- // Tool 1: Query high-risk claimants
2104
- const highRisk = db.querySelect(`
2105
- SELECT ?claimant ?score WHERE {
2106
- ?claimant <http://insurance.org/riskScore> ?score .
2107
- FILTER(?score > 0.7)
2108
- }
2109
- `)
2110
- findings.highRiskClaimants = highRisk.length
2111
-
2112
- // Tool 2: Detect fraud rings
2113
- const gf = new GraphFrame(JSON.stringify(vertices), JSON.stringify(edges))
2114
- findings.triangles = gf.triangleCount()
2115
-
2116
- // Tool 3: Find similar claims
2117
- const embeddings = new EmbeddingService()
2118
- // ... store vectors ...
2119
- const similar = JSON.parse(embeddings.findSimilar('CLM001', 5, 0.5))
2120
- findings.similarClaims = similar.length
2121
-
2122
- // Tool 4: Infer collusion patterns
2123
- const datalog = new DatalogProgram()
2124
- // ... add facts and rules ...
2125
- const inferred = JSON.parse(evaluateDatalog(datalog))
2126
- findings.collusions = (inferred.potential_collusion || []).length
2127
- findings.addressFraud = (inferred.address_fraud_indicator || []).length
2128
-
2129
- // Step 4: Generate Execution Witness
2130
- const witness = {
2131
- agent: agent.getName(),
2132
- model: agent.getModel(),
2133
- timestamp: new Date().toISOString(),
2134
- findings,
2135
- proof_hash: `sha256:${Date.now().toString(16)}`
2136
- }
2137
-
2138
- return { findings, witness }
2139
- }
2140
- ```
2141
-
2142
- ### Run the Complete Examples
2143
-
2144
- ```bash
2145
- # Fraud Detection Agent (full pipeline)
2146
- node examples/fraud-detection-agent.js
2147
-
2148
- # Underwriting Agent (full pipeline)
2149
- node examples/underwriting-agent.js
2150
-
2151
- # With real LLM (Anthropic)
2152
- ANTHROPIC_API_KEY=sk-ant-... node examples/fraud-detection-agent.js
2153
-
2154
- # With real LLM (OpenAI)
2155
- OPENAI_API_KEY=sk-proj-... node examples/underwriting-agent.js
2156
- ```
2157
-
2158
- ### The Complete Picture
2159
-
2160
- ```
2161
- ┌──────────────────────────────────────────────────────────────────────────────┐
2162
- │ HYPERMIND AGENT DESIGN FLOW │
2163
- │ │
2164
- │ ┌─────────────────┐ │
2165
- │ │ Domain Expert │ "Fraud rings create payment triangles" │
2166
- │ │ Knowledge │ "Same address + high risk = address fraud" │
2167
- │ └────────┬────────┘ │
2168
- │ │ │
2169
- │ ▼ │
2170
- │ ┌─────────────────┐ │
2171
- │ │ Knowledge Graph │ RDF/Turtle ontology with NICB patterns │
2172
- │ │ (GraphDB) │ Claims, claimants, providers, relationships │
2173
- │ └────────┬────────┘ │
2174
- │ │ │
2175
- │ ┌────────┴────────────────────────────────────────────┐ │
2176
- │ │ │ │
2177
- │ ▼ ▼ ▼ │
2178
- │ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │
2179
- │ │ GraphFrame │ │ Embeddings │ │ Datalog │ │
2180
- │ │ (Structure) │ │ (Semantics) │ │ (Rules) │ │
2181
- │ │ │ │ │ │ │ │
2182
- │ │ • Triangles │ │ • Similar │ │ • Collusion rule │ │
2183
- │ │ • PageRank │ │ claims │ │ • Address fraud │ │
2184
- │ │ • Components │ │ • Clustering │ │ • Custom rules │ │
2185
- │ └──────┬───────┘ └──────┬───────┘ └────────┬─────────┘ │
2186
- │ │ │ │ │
2187
- │ └──────────────────┼─────────────────────┘ │
2188
- │ │ │
2189
- │ ▼ │
2190
- │ ┌─────────────────┐ │
2191
- │ │ HyperMind Agent│ │
2192
- │ │ Composition │ │
2193
- │ │ │ │
2194
- │ │ Type-safe tools │ │
2195
- │ │ Execution proof │ │
2196
- │ │ Audit trail │ │
2197
- │ └────────┬────────┘ │
2198
- │ │ │
2199
- │ ▼ │
2200
- │ ┌─────────────────┐ │
2201
- │ │ ExecutionWitness│ │
2202
- │ │ │ │
2203
- │ │ • SHA-256 hash │ │
2204
- │ │ • Timestamp │ │
2205
- │ │ • Tool trace │ │
2206
- │ │ • Findings │ │
2207
- │ └─────────────────┘ │
2208
- │ │
2209
- │ RESULT: Auditable, provable, type-safe fraud detection │
2210
- └──────────────────────────────────────────────────────────────────────────────┘
2211
- ```
2212
-
2213
- This is the power of HyperMind: **every step is typed, every execution is witnessed, every result is provable.**
2214
-
2215
- ---
2216
-
2217
- ## API Reference
2218
-
2219
- ### GraphDB
2220
-
2221
- ```typescript
2222
- class GraphDB {
2223
- constructor(baseUri: string)
2224
- loadTtl(ttl: string, graphName: string | null): void
2225
- querySelect(sparql: string): QueryResult[]
2226
- query(sparql: string): TripleResult[]
2227
- countTriples(): number
2228
- clear(): void
2229
- getGraphUri(): string
2230
- }
2231
- ```
2232
-
2233
- ### GraphFrame
2234
-
2235
- ```typescript
2236
- class GraphFrame {
2237
- constructor(verticesJson: string, edgesJson: string)
2238
- vertexCount(): number
2239
- edgeCount(): number
2240
- pageRank(resetProb: number, maxIter: number): string
2241
- connectedComponents(): string
2242
- shortestPaths(landmarks: string[]): string
2243
- labelPropagation(maxIter: number): string
2244
- triangleCount(): number
2245
- find(pattern: string): string
2246
- }
2247
- ```
2248
-
2249
- ### EmbeddingService
2250
-
2251
- ```typescript
2252
- class EmbeddingService {
2253
- constructor()
2254
- isEnabled(): boolean
2255
- storeVector(entityId: string, vector: number[]): void
2256
- getVector(entityId: string): number[] | null
2257
- findSimilar(entityId: string, k: number, threshold: number): string
2258
- rebuildIndex(): void
2259
- storeComposite(entityId: string, embeddingsJson: string): void
2260
- findSimilarComposite(entityId: string, k: number, threshold: number, strategy: string): string
2261
- }
2262
- ```
2263
-
2264
- ### DatalogProgram
2265
-
2266
- ```typescript
2267
- class DatalogProgram {
2268
- constructor()
2269
- addFact(factJson: string): void
2270
- addRule(ruleJson: string): void
2271
- factCount(): number
2272
- ruleCount(): number
2273
- }
2274
-
2275
- function evaluateDatalog(program: DatalogProgram): string
2276
- function queryDatalog(program: DatalogProgram, predicate: string): string
2277
- ```
2278
-
2279
- ---
2280
-
2281
- ## Architecture
2282
-
2283
- ```
2284
- ┌──────────────────────────────────────────────────────────────────┐
2285
- │ Your Application │
2286
- │ (Fraud Detection, Underwriting, Compliance) │
2287
- ├──────────────────────────────────────────────────────────────────┤
2288
- │ rust-kgdb SDK │
2289
- │ GraphDB │ GraphFrame │ Embeddings │ Datalog │ HyperMind │
2290
- ├──────────────────────────────────────────────────────────────────┤
2291
- │ Mathematical Layer │
2292
- │ Type Theory │ Category Theory │ Proof Theory │ WASM Sandbox │
2293
- ├──────────────────────────────────────────────────────────────────┤
2294
- │ Reasoning Layer │
2295
- │ RDFS │ OWL 2 RL │ SHACL │ Datalog │ WCOJ │
2296
- ├──────────────────────────────────────────────────────────────────┤
2297
- │ Storage Layer │
2298
- │ InMemory │ RocksDB │ LMDB │ SPOC Indexes │ Dictionary │
2299
- ├──────────────────────────────────────────────────────────────────┤
2300
- │ Distribution Layer │
2301
- │ HDRF Partitioning │ Raft Consensus │ gRPC │ Kubernetes │
2302
- └──────────────────────────────────────────────────────────────────┘
2303
- ```
2304
-
2305
- ---
2306
-
2307
- ## Critical Business Cannot Be Built on "Vibe Coding"
2308
-
2309
- ```
2310
- ╔═══════════════════════════════════════════════════════════════════════════════╗
2311
- ║ ║
2312
- ║ "It works on my laptop" is not a deployment strategy. ║
2313
- ║ "The LLM usually gets it right" is not acceptable for compliance. ║
2314
- ║ "We'll fix it in production" is how companies get fined. ║
2315
- ║ ║
2316
- ╠═══════════════════════════════════════════════════════════════════════════════╣
2317
- ║ ║
2318
- ║ VIBE CODING (LangChain, AutoGPT, etc.): ║
2319
- ║ ║
2320
- ║ • "Let's just call the LLM and hope" → 0% SPARQL accuracy ║
2321
- ║ • "Tools are just functions" → Runtime type errors ║
2322
- ║ • "We'll add validation later" → Production failures ║
2323
- ║ • "The AI will figure it out" → Infinite loops ║
2324
- ║ • "We don't need proofs" → No audit trail ║
2325
- ║ ║
2326
- ║ Result: Fails FDA, SOX, GDPR audits. Gets you fired. ║
2327
- ║ ║
2328
- ╠═══════════════════════════════════════════════════════════════════════════════╣
2329
- ║ ║
2330
- ║ HYPERMIND (Mathematical Foundations): ║
2331
- ║ ║
2332
- ║ • Type Theory: Errors caught at compile-time → 86.4% SPARQL accuracy ║
2333
- ║ • Category Theory: Morphism composition → No runtime type errors ║
2334
- ║ • Proof Theory: ExecutionWitness for every call → Full audit trail ║
2335
- ║ • WASM Sandbox: Isolated execution → Zero attack surface ║
2336
- ║ • WCOJ Algorithm: Optimal joins → Predictable performance ║
2337
- ║ ║
2338
- ║ Result: Passes audits. Ships to production. Keeps your job. ║
2339
- ║ ║
2340
- ╚═══════════════════════════════════════════════════════════════════════════════╝
2341
- ```
2342
-
2343
- ---
2344
-
2345
- ## On AGI, Prompt Optimization, and Mathematical Foundations
2346
-
2347
- ### The AGI Distraction
2348
-
2349
- While the industry chases AGI (Artificial General Intelligence) with increasingly large models and prompt tricks, **production systems need correctness NOW** - not eventually, not probably, not "when the model gets better."
2350
-
2351
- HyperMind takes a different stance: **We don't need AGI. We need provably correct tool composition.**
2352
-
2353
- ```
2354
- AGI Promise: "Someday the model will understand everything"
2355
- HyperMind Reality: "Today the system PROVES every operation is type-safe"
2356
- ```
2357
-
2358
- ### DSPy and Prompt Optimization: A Fundamental Misunderstanding
2359
-
2360
- **DSPy** and similar frameworks optimize prompts through gradient descent and few-shot learning. This is essentially **curve fitting on text** - statistical optimization, not logical proof.
2361
-
2362
- ```
2363
- DSPy Approach:
2364
- ┌─────────────────────────────────────────────────────────────┐
2365
- │ Input examples → Optimize prompt → Better outputs │
2366
- │ │
2367
- │ Problem: "Better" is measured statistically │
2368
- │ Problem: No guarantee on unseen inputs │
2369
- │ Problem: Prompt drift over model updates │
2370
- │ Problem: Cannot explain WHY it works │
2371
- └─────────────────────────────────────────────────────────────┘
2372
-
2373
- HyperMind Approach:
2374
- ┌─────────────────────────────────────────────────────────────┐
2375
- │ Type signature → Morphism composition → Proven output │
2376
- │ │
2377
- │ Guarantee: Type A in → Type B out (always) │
2378
- │ Guarantee: Composition laws hold (associativity, id) │
2379
- │ Guarantee: Execution witness (proof of correctness) │
2380
- │ Guarantee: Explainable via Curry-Howard correspondence │
2381
- └─────────────────────────────────────────────────────────────┘
2382
- ```
2383
-
2384
- ### Why Prompt Optimization is the Wrong Abstraction
2385
-
2386
- | Approach | Foundation | Guarantee | Audit |
2387
- |----------|------------|-----------|-------|
2388
- | **Prompt Optimization (DSPy)** | Statistical fitting | Probabilistic | None |
2389
- | **Chain-of-Thought** | Heuristic patterns | Hope-based | None |
2390
- | **Few-Shot Learning** | Example matching | Similarity-based | None |
2391
- | **HyperMind** | Type Theory + Category Theory | Mathematical proof | Full witness |
2392
-
2393
- **The hard truth:**
2394
-
2395
- ```
2396
- Prompt optimization CANNOT prove:
2397
- × That a tool chain terminates
2398
- × That intermediate types are compatible
2399
- × That the result satisfies business constraints
2400
- × That the execution is deterministic
2401
-
2402
- HyperMind PROVES:
2403
- ✓ Tool chains form valid morphism compositions
2404
- ✓ Types are checked at compile-time (Hindley-Milner)
2405
- ✓ Business constraints are refinement types
2406
- ✓ Every execution has a cryptographic witness
2407
- ```
2408
-
2409
- ### The Mathematical Difference
2410
-
2411
- **DSPy** says: *"Let's tune the prompt until outputs look right"*
2412
- **HyperMind** says: *"Let's prove the types align, and correctness follows"*
2413
-
2414
- ```
2415
- DSPy: P(correct | prompt, examples) ≈ 0.85 (probabilistic)
2416
- HyperMind: ∀x:A. f(x):B (universal quantifier - ALWAYS)
2417
- ```
2418
-
2419
- This isn't academic distinction. When your fraud detection system flags 15 suspicious patterns, the regulator asks: *"How do you know these are correct?"*
2420
-
2421
- - **DSPy answer**: "Our test set accuracy was 85%"
2422
- - **HyperMind answer**: "Here's the ExecutionWitness with SHA-256 hash, timestamp, and full type derivation"
2423
-
2424
- One passes audit. One doesn't.
2425
-
2426
- ---
2427
-
2428
- ## Code Comparison: DSPy vs HyperMind
2429
-
2430
- ### DSPy Approach (Prompt Optimization)
2431
-
2432
- ```python
2433
- # DSPy: Statistically optimized prompt - NO guarantees
2434
-
2435
- import dspy
2436
-
2437
- class FraudDetector(dspy.Signature):
2438
- """Find fraud patterns in claims data."""
2439
- claims_data = dspy.InputField()
2440
- fraud_patterns = dspy.OutputField()
2441
-
2442
- class FraudPipeline(dspy.Module):
2443
- def __init__(self):
2444
- self.detector = dspy.ChainOfThought(FraudDetector)
2445
-
2446
- def forward(self, claims):
2447
- return self.detector(claims_data=claims)
2448
-
2449
- # "Optimize" via statistical fitting
2450
- optimizer = dspy.BootstrapFewShot(metric=some_metric)
2451
- optimized = optimizer.compile(FraudPipeline(), trainset=examples)
2452
-
2453
- # Call and HOPE it works
2454
- result = optimized(claims="[claim data here]")
2455
-
2456
- # ❌ No type guarantee - fraud_patterns could be anything
2457
- # ❌ No proof of execution - just text output
2458
- # ❌ No composition safety - next step might fail
2459
- # ❌ No audit trail - "it said fraud" is not compliance
2460
- ```
2461
-
2462
- **What DSPy produces:** A string that *probably* contains fraud patterns.
2463
-
2464
- ### HyperMind Approach (Mathematical Proof)
2465
-
2466
- ```javascript
2467
- // HyperMind: Type-safe morphism composition - PROVEN correct
2468
-
2469
- const { GraphDB, GraphFrame, DatalogProgram, evaluateDatalog } = require('rust-kgdb')
2470
-
2471
- // Step 1: Load typed knowledge graph (Schema enforced)
2472
- const db = new GraphDB('http://insurance.org/fraud-kb')
2473
- db.loadTtl(`
2474
- @prefix : <http://insurance.org/> .
2475
- :CLM001 :amount "18500" ; :claimant :P001 ; :provider :PROV001 .
2476
- :P001 :paidTo :P002 .
2477
- :P002 :paidTo :P003 .
2478
- :P003 :paidTo :P001 .
2479
- `, null)
2480
-
2481
- // Step 2: GraphFrame analysis (Morphism: Graph → TriangleCount)
2482
- // Type signature: GraphFrame → number (guaranteed)
2483
- const graph = new GraphFrame(
2484
- JSON.stringify([{id:'P001'}, {id:'P002'}, {id:'P003'}]),
2485
- JSON.stringify([
2486
- {src:'P001', dst:'P002'},
2487
- {src:'P002', dst:'P003'},
2488
- {src:'P003', dst:'P001'}
2489
- ])
2490
- )
2491
- const triangles = graph.triangleCount() // Type: number (always)
2492
-
2493
- // Step 3: Datalog inference (Morphism: Rules → Facts)
2494
- // Type signature: DatalogProgram → InferredFacts (guaranteed)
2495
- const datalog = new DatalogProgram()
2496
- datalog.addFact(JSON.stringify({predicate:'claim', terms:['CLM001','P001','PROV001']}))
2497
- datalog.addFact(JSON.stringify({predicate:'related', terms:['P001','P002']}))
2498
-
2499
- datalog.addRule(JSON.stringify({
2500
- head: {predicate:'collusion', terms:['?P1','?P2','?Prov']},
2501
- body: [
2502
- {predicate:'claim', terms:['?C1','?P1','?Prov']},
2503
- {predicate:'claim', terms:['?C2','?P2','?Prov']},
2504
- {predicate:'related', terms:['?P1','?P2']}
2505
- ]
2506
- }))
2507
-
2508
- const result = JSON.parse(evaluateDatalog(datalog))
2509
-
2510
- // ✓ Type guarantee: result.collusion is always array of tuples
2511
- // ✓ Proof of execution: Datalog evaluation is deterministic
2512
- // ✓ Composition safety: Each step has typed input/output
2513
- // ✓ Audit trail: Every fact derivation is traceable
2514
- ```
2515
-
2516
- **What HyperMind produces:** Typed results with mathematical proof of derivation.
2517
-
2518
- ### Actual Output Comparison
2519
-
2520
- **DSPy Output:**
2521
- ```
2522
- fraud_patterns: "I found some suspicious patterns involving P001 and P002
2523
- that appear to be related. There might be collusion with provider PROV001."
2524
- ```
2525
- *How do you validate this? You can't. It's text.*
2526
-
2527
- **HyperMind Output:**
2528
- ```json
2529
- {
2530
- "triangles": 1,
2531
- "collusion": [["P001", "P002", "PROV001"]],
2532
- "executionWitness": {
2533
- "tool": "datalog.evaluate",
2534
- "input": "6 facts, 1 rule",
2535
- "output": "collusion(P001,P002,PROV001)",
2536
- "derivation": "claim(CLM001,P001,PROV001) ∧ claim(CLM002,P002,PROV001) ∧ related(P001,P002) → collusion(P001,P002,PROV001)",
2537
- "timestamp": "2024-12-14T10:30:00Z",
2538
- "semanticHash": "semhash:collusion-p001-p002-prov001"
2539
- }
2540
- }
2541
- ```
2542
- *Every result has a logical derivation and cryptographic proof.*
2543
-
2544
- ### The Compliance Question
2545
-
2546
- **Auditor:** "How do you know P001-P002-PROV001 is actually collusion?"
2547
-
2548
- **DSPy Team:** "Our model said so. It was trained on examples and optimized for accuracy."
2549
-
2550
- **HyperMind Team:** "Here's the derivation chain:
2551
- 1. `claim(CLM001, P001, PROV001)` - fact from data
2552
- 2. `claim(CLM002, P002, PROV001)` - fact from data
2553
- 3. `related(P001, P002)` - fact from data
2554
- 4. Rule: `collusion(?P1, ?P2, ?Prov) :- claim(?C1, ?P1, ?Prov), claim(?C2, ?P2, ?Prov), related(?P1, ?P2)`
2555
- 5. Unification: `?P1=P001, ?P2=P002, ?Prov=PROV001`
2556
- 6. Conclusion: `collusion(P001, P002, PROV001)` - QED
2557
-
2558
- Here's the semantic hash: `semhash:collusion-p001-p002-prov001` - same query intent will always return this exact result."
2559
-
2560
- **Result:** HyperMind passes audit. DSPy gets you a follow-up meeting with legal.
2561
-
2562
- ### The Stack That Matters
2563
-
2564
- ```
2565
- ┌───────────────────────────────────────────────────────────────────────────────┐
2566
- │ │
2567
- │ HYPERMIND AGENT (this is what you build with) │
2568
- │ ├── Natural language → structured queries │
2569
- │ ├── 86.4% accuracy on complex SPARQL generation │
2570
- │ └── Full provenance for every decision │
2571
- │ │
2572
- ├───────────────────────────────────────────────────────────────────────────────┤
2573
- │ │
2574
- │ KNOWLEDGE GRAPH DATABASE (this is what powers it) │
2575
- │ ├── 2.78 µs lookups (35x faster than RDFox) │
2576
- │ ├── 24 bytes/triple (25% more efficient) │
2577
- │ ├── W3C SPARQL 1.1 + RDF 1.2 (100% compliance) │
2578
- │ ├── RDFS + OWL 2 RL reasoners (ontology inference) │
2579
- │ ├── SHACL validation (schema enforcement) │
2580
- │ └── WCOJ algorithm (worst-case optimal joins) │
2581
- │ │
2582
- ├───────────────────────────────────────────────────────────────────────────────┤
2583
- │ │
2584
- │ DISTRIBUTION LAYER (this is how it scales) │
2585
- │ ├── Mobile: iOS + Android with zero-copy FFI │
2586
- │ ├── Standalone: Single node with RocksDB/LMDB │
2587
- │ └── Clustered: Kubernetes with HDRF + Raft consensus │
2588
- │ │
2589
- └───────────────────────────────────────────────────────────────────────────────┘
2590
- ```
2591
-
2592
- ---
2593
-
2594
- ## Why This Matters
2595
-
2596
- ```
2597
- ┌─────────────────────────────────────────────────────────────────┐
2598
- │ COMPETITIVE LANDSCAPE │
2599
- ├─────────────────────────────────────────────────────────────────┤
2600
- │ │
2601
- │ Apache Jena: Great features, but 150+ µs lookups │
2602
- │ RDFox: Fast, but expensive and no mobile support │
2603
- │ Neo4j: Popular, but no SPARQL/RDF standards │
2604
- │ Amazon Neptune: Managed, but cloud-only vendor lock-in │
2605
- │ LangChain: Vibe coding, fails compliance audits │
2606
- │ │
2607
- │ rust-kgdb: 2.78 µs lookups, mobile-native, open standards │
2608
- │ Standalone → Clustered on same codebase │
2609
- │ Mathematical foundations, audit-ready │
2610
- │ │
2611
- └─────────────────────────────────────────────────────────────────┘
2612
- ```
2613
-
2614
- ---
2615
-
2616
- ## Contact
2617
-
2618
- **Email:** gonnect.uk@gmail.com
2619
-
2620
- **GitHub:** [github.com/gonnect-uk/rust-kgdb](https://github.com/gonnect-uk/rust-kgdb)
2621
-
2622
- **npm:** [npmjs.com/package/rust-kgdb](https://www.npmjs.com/package/rust-kgdb)
2623
-
2624
- ---
2625
-
2626
- ## License
2627
-
2628
- Apache-2.0
2629
-
2630
- ---
2631
-
2632
- *Built with Rust. Grounded in mathematics. Ready for production.*