rust-kgdb 0.6.61 → 0.6.62

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.
Files changed (2) hide show
  1. package/README.md +160 -160
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -56,13 +56,13 @@ The AI translates intent into queries. The database finds facts. The AI never ma
56
56
  ```
57
57
  Before (Dangerous):
58
58
  Human: "Is Provider #4521 suspicious?"
59
- AI: "Yes, they have billing anomalies" FABRICATED
59
+ AI: "Yes, they have billing anomalies" <- FABRICATED
60
60
 
61
61
  After (Safe):
62
62
  Human: "Is Provider #4521 suspicious?"
63
- AI: Generates SPARQL query Executes against YOUR database
63
+ AI: Generates SPARQL query -> Executes against YOUR database
64
64
  Database: Returns actual facts about Provider #4521
65
- Result: Real data with audit trail VERIFIABLE
65
+ Result: Real data with audit trail <- VERIFIABLE
66
66
  ```
67
67
 
68
68
  rust-kgdb is a knowledge graph database with an AI layer that **cannot hallucinate** because it only returns data from your actual systems.
@@ -102,18 +102,18 @@ rust-kgdb is a knowledge graph database with an AI layer that **cannot hallucina
102
102
  A high-performance RDF/SPARQL database that runs **inside your application**. No server. No Docker. No config.
103
103
 
104
104
  ```
105
- ┌─────────────────────────────────────────────────────────────────────────────┐
106
- rust-kgdb CORE ENGINE
107
-
108
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
109
- GraphDB GraphFrame Embeddings Datalog
110
- (SPARQL) (Analytics) (HNSW) (Reasoning)
111
- 449ns PageRank 16ms/10K Semi-naive
112
- └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
113
-
114
- Storage: InMemory | RocksDB | LMDB Standards: SPARQL 1.1 | RDF 1.2
115
- Memory: 24 bytes/triple Compliance: SHACL | PROV | OWL 2 RL
116
- └─────────────────────────────────────────────────────────────────────────────┘
105
+ +-----------------------------------------------------------------------------+
106
+ | rust-kgdb CORE ENGINE |
107
+ | |
108
+ | +-------------+ +-------------+ +-------------+ +-------------+ |
109
+ | | GraphDB | | GraphFrame | | Embeddings | | Datalog | |
110
+ | | (SPARQL) | | (Analytics) | | (HNSW) | | (Reasoning) | |
111
+ | | 449ns | | PageRank | | 16ms/10K | | Semi-naive | |
112
+ | +-------------+ +-------------+ +-------------+ +-------------+ |
113
+ | |
114
+ | Storage: InMemory | RocksDB | LMDB Standards: SPARQL 1.1 | RDF 1.2 |
115
+ | Memory: 24 bytes/triple Compliance: SHACL | PROV | OWL 2 RL |
116
+ +-----------------------------------------------------------------------------+
117
117
  ```
118
118
 
119
119
  **Performance (Verified on LUBM benchmark):**
@@ -132,18 +132,18 @@ A high-performance RDF/SPARQL database that runs **inside your application**. No
132
132
  An AI agent layer that uses **the database to prevent hallucinations**. The LLM plans, the database executes.
133
133
 
134
134
  ```
135
- ┌─────────────────────────────────────────────────────────────────────────────┐
136
- HYPERMIND AGENT FRAMEWORK
137
-
138
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
139
- LLMPlanner WasmSandbox ProofDAG Memory
140
- (Claude/GPT) (Security) (Audit) (Hypergraph)
141
- └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
142
-
143
- Type Theory: Hindley-Milner types ensure tool composition is valid
144
- Category Theory: Tools are morphisms (A B) with composition laws
145
- Proof Theory: Every execution produces cryptographic audit trail
146
- └─────────────────────────────────────────────────────────────────────────────┘
135
+ +-----------------------------------------------------------------------------+
136
+ | HYPERMIND AGENT FRAMEWORK |
137
+ | |
138
+ | +-------------+ +-------------+ +-------------+ +-------------+ |
139
+ | | LLMPlanner | | WasmSandbox | | ProofDAG | | Memory | |
140
+ | | (Claude/GPT)| | (Security) | | (Audit) | | (Hypergraph)| |
141
+ | +-------------+ +-------------+ +-------------+ +-------------+ |
142
+ | |
143
+ | Type Theory: Hindley-Milner types ensure tool composition is valid |
144
+ | Category Theory: Tools are morphisms (A -> B) with composition laws |
145
+ | Proof Theory: Every execution produces cryptographic audit trail |
146
+ +-----------------------------------------------------------------------------+
147
147
  ```
148
148
 
149
149
  **Agent Accuracy (LUBM Benchmark - 14 Queries, 3,272 Triples):**
@@ -215,25 +215,25 @@ Traditional AI tool calling (OpenAI Functions, LangChain Tools) has fundamental
215
215
 
216
216
  **The Traditional Approach:**
217
217
  ```
218
- LLM generates JSON Runtime validates schema Tool executes Hope it works
218
+ LLM generates JSON -> Runtime validates schema -> Tool executes -> Hope it works
219
219
  ```
220
220
 
221
221
  1. **Schema is decorative.** The LLM sees a JSON schema and tries to match it. No guarantee outputs are correct types.
222
- 2. **Composition is ad-hoc.** Chain Tool A Tool B? Pray that A's output format happens to match B's input.
222
+ 2. **Composition is ad-hoc.** Chain Tool A -> Tool B? Pray that A's output format happens to match B's input.
223
223
  3. **Errors happen at runtime.** You find out a tool chain is broken when a user hits it in production.
224
224
  4. **No mathematical guarantees.** "It usually works" is the best you get.
225
225
 
226
226
  **Our Approach: Tools as Typed Morphisms**
227
227
  ```
228
228
  Tools are arrows in a category:
229
- kg.sparql.query: Query BindingSet
230
- kg.motif.find: Pattern Matches
231
- kg.embeddings.search: EntityId SimilarEntities
229
+ kg.sparql.query: Query -> BindingSet
230
+ kg.motif.find: Pattern -> Matches
231
+ kg.embeddings.search: EntityId -> SimilarEntities
232
232
 
233
233
  Composition is verified:
234
- f: A B
235
- g: B C
236
- g f: A C Compiles only if types match
234
+ f: A -> B
235
+ g: B -> C
236
+ g o f: A -> C [x] Compiles only if types match
237
237
 
238
238
  Errors caught at plan time, not runtime.
239
239
  ```
@@ -262,49 +262,49 @@ The type system *guarantees* a tool that outputs `RiskScore` produces a valid ri
262
262
 
263
263
  Traditional tool calling trusts the LLM output completely:
264
264
  ```
265
- LLM Tool (direct execution) Result
265
+ LLM -> Tool (direct execution) -> Result
266
266
  ```
267
267
 
268
268
  The LLM decides what to execute. The tool runs it blindly. This is why prompt injection attacks work - the LLM's output *is* the program.
269
269
 
270
- **Our approach: Agent Proxy Sandbox Tool**
270
+ **Our approach: Agent -> Proxy -> Sandbox -> Tool**
271
271
  ```
272
- ┌─────────────────────────────────────────────────────────────────────┐
273
- Agent Request: "Find suspicious claims"
274
- └────────────────────────────┬────────────────────────────────────────┘
275
-
276
-
277
- ┌─────────────────────────────────────────────────────────────────────┐
278
- LLMPlanner: Generates tool call plan
279
- kg.sparql.query(pattern)
280
- kg.datalog.infer(rules)
281
- └────────────────────────────┬────────────────────────────────────────┘
282
- Plan (NOT executed yet)
283
-
284
- ┌─────────────────────────────────────────────────────────────────────┐
285
- HyperAgentProxy: Validates plan against capabilities
286
- Does agent have ReadKG capability? Yes
287
- Is query schema-valid? Yes
288
- Are all types correct? Yes
289
- Blocked: WriteKG not in capability set
290
- └────────────────────────────┬────────────────────────────────────────┘
291
- Validated plan only
292
-
293
- ┌─────────────────────────────────────────────────────────────────────┐
294
- WasmSandbox: Executes with resource limits
295
- Fuel metering: 1M operations max
296
- Memory cap: 64MB
297
- Capability enforcement: Cannot exceed granted permissions
298
- └────────────────────────────┬────────────────────────────────────────┘
299
- Execution with audit
300
-
301
- ┌─────────────────────────────────────────────────────────────────────┐
302
- ProofDAG: Records execution witness
303
- What tool ran
304
- What inputs were used
305
- What outputs were produced
306
- SHA-256 hash of entire execution
307
- └─────────────────────────────────────────────────────────────────────┘
272
+ +---------------------------------------------------------------------+
273
+ | Agent Request: "Find suspicious claims" |
274
+ +----------------------------+----------------------------------------+
275
+ |
276
+ v
277
+ +---------------------------------------------------------------------+
278
+ | LLMPlanner: Generates tool call plan |
279
+ | -> kg.sparql.query(pattern) |
280
+ | -> kg.datalog.infer(rules) |
281
+ +----------------------------+----------------------------------------+
282
+ | Plan (NOT executed yet)
283
+ v
284
+ +---------------------------------------------------------------------+
285
+ | HyperAgentProxy: Validates plan against capabilities |
286
+ | [x] Does agent have ReadKG capability? Yes |
287
+ | [x] Is query schema-valid? Yes |
288
+ | [x] Are all types correct? Yes |
289
+ | [ ] Blocked: WriteKG not in capability set |
290
+ +----------------------------+----------------------------------------+
291
+ | Validated plan only
292
+ v
293
+ +---------------------------------------------------------------------+
294
+ | WasmSandbox: Executes with resource limits |
295
+ | * Fuel metering: 1M operations max |
296
+ | * Memory cap: 64MB |
297
+ | * Capability enforcement: Cannot exceed granted permissions |
298
+ +----------------------------+----------------------------------------+
299
+ | Execution with audit
300
+ v
301
+ +---------------------------------------------------------------------+
302
+ | ProofDAG: Records execution witness |
303
+ | * What tool ran |
304
+ | * What inputs were used |
305
+ | * What outputs were produced |
306
+ | * SHA-256 hash of entire execution |
307
+ +---------------------------------------------------------------------+
308
308
  ```
309
309
 
310
310
  The LLM never executes directly. It proposes. The proxy validates. The sandbox enforces. The proof records. Four independent layers of defense.
@@ -384,38 +384,38 @@ console.log(result.evidence);
384
384
  ## Architecture: Two Layers
385
385
 
386
386
  ```
387
- ┌─────────────────────────────────────────────────────────────────────────────────┐
388
- YOUR APPLICATION
389
- (Fraud Detection, Underwriting, Compliance)
390
- └────────────────────────────────────┬────────────────────────────────────────────┘
391
-
392
- ┌────────────────────────────────────▼────────────────────────────────────────────┐
393
- HYPERMIND AGENT FRAMEWORK (JavaScript)
394
- ┌────────────────────────────────────────────────────────────────────────────┐
395
- LLMPlanner: Natural language typed tool pipelines
396
- WasmSandbox: Capability-based security with fuel metering
397
- ProofDAG: Cryptographic audit trail (SHA-256)
398
- MemoryHypergraph: Temporal agent memory with KG integration
399
- TypeId: Hindley-Milner type system with refinement types
400
- └────────────────────────────────────────────────────────────────────────────┘
401
-
402
- Category Theory: Tools as Morphisms (A B)
403
- Proof Theory: Every execution has a witness
404
- └────────────────────────────────────┬────────────────────────────────────────────┘
405
- NAPI-RS Bindings
406
- ┌────────────────────────────────────▼────────────────────────────────────────────┐
407
- RUST CORE ENGINE (Native Performance)
408
- ┌────────────────────────────────────────────────────────────────────────────┐
409
- GraphDB RDF/SPARQL quad store 449ns lookups, 24 bytes/triple
410
- GraphFrame Graph algorithms WCOJ optimal joins, PageRank
411
- EmbeddingService Vector similarity HNSW index, 1-hop ARCADE cache
412
- DatalogProgram Rule-based reasoning Semi-naive evaluation
413
- Pregel BSP graph processing Billion-edge scale
414
- └────────────────────────────────────────────────────────────────────────────┘
415
-
416
- W3C Standards: SPARQL 1.1 (100%) | RDF 1.2 | OWL 2 RL | SHACL | PROV
417
- Storage Backends: InMemory | RocksDB | LMDB
418
- └──────────────────────────────────────────────────────────────────────────────────┘
387
+ +---------------------------------------------------------------------------------+
388
+ | YOUR APPLICATION |
389
+ | (Fraud Detection, Underwriting, Compliance) |
390
+ +------------------------------------+--------------------------------------------+
391
+ |
392
+ +------------------------------------v--------------------------------------------+
393
+ | HYPERMIND AGENT FRAMEWORK (JavaScript) |
394
+ | +----------------------------------------------------------------------------+ |
395
+ | | * LLMPlanner: Natural language -> typed tool pipelines | |
396
+ | | * WasmSandbox: Capability-based security with fuel metering | |
397
+ | | * ProofDAG: Cryptographic audit trail (SHA-256) | |
398
+ | | * MemoryHypergraph: Temporal agent memory with KG integration | |
399
+ | | * TypeId: Hindley-Milner type system with refinement types | |
400
+ | +----------------------------------------------------------------------------+ |
401
+ | |
402
+ | Category Theory: Tools as Morphisms (A -> B) |
403
+ | Proof Theory: Every execution has a witness |
404
+ +------------------------------------+--------------------------------------------+
405
+ | NAPI-RS Bindings
406
+ +------------------------------------v--------------------------------------------+
407
+ | RUST CORE ENGINE (Native Performance) |
408
+ | +----------------------------------------------------------------------------+ |
409
+ | | GraphDB | RDF/SPARQL quad store | 449ns lookups, 24 bytes/triple|
410
+ | | GraphFrame | Graph algorithms | WCOJ optimal joins, PageRank |
411
+ | | EmbeddingService | Vector similarity | HNSW index, 1-hop ARCADE cache|
412
+ | | DatalogProgram | Rule-based reasoning | Semi-naive evaluation |
413
+ | | Pregel | BSP graph processing | Billion-edge scale |
414
+ | +----------------------------------------------------------------------------+ |
415
+ | |
416
+ | W3C Standards: SPARQL 1.1 (100%) | RDF 1.2 | OWL 2 RL | SHACL | PROV |
417
+ | Storage Backends: InMemory | RocksDB | LMDB |
418
+ +----------------------------------------------------------------------------------+
419
419
  ```
420
420
 
421
421
  ---
@@ -539,15 +539,15 @@ const distances = pregelShortestPaths(graph, 'v0', 100);
539
539
  User: "Find all professors"
540
540
 
541
541
  Vanilla LLM Output:
542
- ┌───────────────────────────────────────────────────────────────────────┐
543
- ```sparql
544
- SELECT ?professor WHERE { ?professor a ub:Faculty . }
545
- ``` Parser rejects markdown
546
-
547
- This query retrieves faculty members.
548
- Mixed text breaks parsing
549
- └───────────────────────────────────────────────────────────────────────┘
550
- Result: PARSER ERROR - Invalid SPARQL syntax
542
+ +-----------------------------------------------------------------------+
543
+ | ```sparql |
544
+ | SELECT ?professor WHERE { ?professor a ub:Faculty . } |
545
+ | ``` <- Parser rejects markdown |
546
+ | |
547
+ | This query retrieves faculty members. |
548
+ | ^ Mixed text breaks parsing |
549
+ +-----------------------------------------------------------------------+
550
+ Result: FAIL PARSER ERROR - Invalid SPARQL syntax
551
551
  ```
552
552
 
553
553
  **Problems:** (1) Markdown code fences, (2) Wrong class name (Faculty vs Professor), (3) Mixed text
@@ -558,11 +558,11 @@ Result: ❌ PARSER ERROR - Invalid SPARQL syntax
558
558
  User: "Find all professors"
559
559
 
560
560
  HyperMind Output:
561
- ┌───────────────────────────────────────────────────────────────────────┐
562
- PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
563
- SELECT ?professor WHERE { ?professor a ub:Professor . }
564
- └───────────────────────────────────────────────────────────────────────┘
565
- Result: 15 results returned in 2.3ms
561
+ +-----------------------------------------------------------------------+
562
+ | PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> |
563
+ | SELECT ?professor WHERE { ?professor a ub:Professor . } |
564
+ +-----------------------------------------------------------------------+
565
+ Result: OK 15 results returned in 2.3ms
566
566
  ```
567
567
 
568
568
  **Why it works:**
@@ -570,7 +570,7 @@ Result: ✅ 15 results returned in 2.3ms
570
570
  2. **Type-checked** - Query validated before execution
571
571
  3. **No text pollution** - Output is pure SPARQL, not markdown
572
572
 
573
- **Accuracy: 0% 86.4%** (LUBM benchmark, 14 queries)
573
+ **Accuracy: 0% -> 86.4%** (LUBM benchmark, 14 queries)
574
574
 
575
575
  ### Agent Components
576
576
 
@@ -613,10 +613,10 @@ const sandbox = new WasmSandbox({
613
613
  });
614
614
 
615
615
  // All tool calls are:
616
- // Capability-checked
617
- // Fuel-metered
618
- // Memory-bounded
619
- // Logged for audit
616
+ // [x] Capability-checked
617
+ // [x] Fuel-metered
618
+ // [x] Memory-bounded
619
+ // [x] Logged for audit
620
620
  ```
621
621
 
622
622
  ### Execution Witness (Audit Trail)
@@ -651,30 +651,30 @@ Most AI agents have amnesia. Ask the same question twice, they start from scratc
651
651
  ### Our Solution: Memory Hypergraph
652
652
 
653
653
  ```
654
- ┌─────────────────────────────────────────────────────────────────────────────┐
655
- MEMORY HYPERGRAPH
656
-
657
- AGENT MEMORY LAYER
658
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
659
- Episode:001 Episode:002 Episode:003
660
- "Fraud ring "Denied "Follow-up
661
- detected" claim" on P001"
662
- Dec 10 Dec 12 Dec 15
663
- └──────┬──────┘ └──────┬──────┘ └──────┬──────┘
664
-
665
- └───────────────────┼───────────────────┘
666
- HyperEdges connect to KG
667
-
668
- KNOWLEDGE GRAPH LAYER
669
- ┌─────────────────────────────────────────────────────────────────────┐
670
- Provider:P001 ──────▶ Claim:C123 ◀────── Claimant:John
671
-
672
-
673
- riskScore: 0.87 amount: 50000 address: "123 Main"
674
- └─────────────────────────────────────────────────────────────────────┘
675
-
676
- SAME QUAD STORE - Single SPARQL query traverses BOTH!
677
- └─────────────────────────────────────────────────────────────────────────────┘
654
+ +-----------------------------------------------------------------------------+
655
+ | MEMORY HYPERGRAPH |
656
+ | |
657
+ | AGENT MEMORY LAYER |
658
+ | +-------------+ +-------------+ +-------------+ |
659
+ | | Episode:001 | | Episode:002 | | Episode:003 | |
660
+ | | "Fraud ring | | "Denied | | "Follow-up | |
661
+ | | detected" | | claim" | | on P001" | |
662
+ | | Dec 10 | | Dec 12 | | Dec 15 | |
663
+ | +------+------+ +------+------+ +------+------+ |
664
+ | | | | |
665
+ | +-------------------+-------------------+ |
666
+ | | HyperEdges connect to KG |
667
+ | v |
668
+ | KNOWLEDGE GRAPH LAYER |
669
+ | +---------------------------------------------------------------------+ |
670
+ | | Provider:P001 ------> Claim:C123 <------ Claimant:John | |
671
+ | | | | | | |
672
+ | | v v v | |
673
+ | | riskScore: 0.87 amount: 50000 address: "123 Main" | |
674
+ | +---------------------------------------------------------------------+ |
675
+ | |
676
+ | SAME QUAD STORE - Single SPARQL query traverses BOTH! |
677
+ +-----------------------------------------------------------------------------+
678
678
  ```
679
679
 
680
680
  ### Benchmarked Performance
@@ -696,7 +696,7 @@ const result1 = await agent.call("Analyze claims from Provider P001");
696
696
 
697
697
  // Second call (different wording): Cache HIT!
698
698
  const result2 = await agent.call("Show me P001's claim patterns");
699
- // Same semantic hash Same result
699
+ // Same semantic hash -> Same result
700
700
  ```
701
701
 
702
702
  ---
@@ -707,18 +707,18 @@ const result2 = await agent.call("Show me P001's claim patterns");
707
707
 
708
708
  ```
709
709
  Tools are typed arrows:
710
- kg.sparql.query: Query BindingSet
711
- kg.motif.find: Pattern Matches
712
- kg.datalog.apply: Rules InferredFacts
710
+ kg.sparql.query: Query -> BindingSet
711
+ kg.motif.find: Pattern -> Matches
712
+ kg.datalog.apply: Rules -> InferredFacts
713
713
 
714
714
  Composition is type-checked:
715
- f: A B
716
- g: B C
717
- g f: A C (valid only if B matches)
715
+ f: A -> B
716
+ g: B -> C
717
+ g o f: A -> C (valid only if B matches)
718
718
 
719
719
  Laws guaranteed:
720
- Identity: id f = f
721
- Associativity: (h g) f = h (g f)
720
+ Identity: id o f = f
721
+ Associativity: (h o g) o f = h o (g o f)
722
722
  ```
723
723
 
724
724
  **In practice:** The AI can only chain tools where outputs match inputs. Like Lego blocks that must fit.
@@ -1145,8 +1145,8 @@ console.log('Underwriting decisions:', decisions);
1145
1145
  ```javascript
1146
1146
  const db = new GraphDB(baseUri) // Create database
1147
1147
  db.loadTtl(turtle, graphUri) // Load Turtle data
1148
- db.querySelect(sparql) // SELECT query [{bindings}]
1149
- db.queryConstruct(sparql) // CONSTRUCT query triples
1148
+ db.querySelect(sparql) // SELECT query -> [{bindings}]
1149
+ db.queryConstruct(sparql) // CONSTRUCT query -> triples
1150
1150
  db.countTriples() // Total triple count
1151
1151
  db.clear() // Clear all data
1152
1152
  db.getVersion() // SDK version
@@ -1180,7 +1180,7 @@ emb.getNeighborsOut(entityId) // Get outgoing neighbors
1180
1180
  const dl = new DatalogProgram()
1181
1181
  dl.addFact(factJson) // Add fact
1182
1182
  dl.addRule(ruleJson) // Add rule
1183
- evaluateDatalog(dl) // Run evaluation facts JSON
1183
+ evaluateDatalog(dl) // Run evaluation -> facts JSON
1184
1184
  queryDatalog(dl, queryJson) // Query specific predicate
1185
1185
  ```
1186
1186
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rust-kgdb",
3
- "version": "0.6.61",
3
+ "version": "0.6.62",
4
4
  "description": "High-performance RDF/SPARQL database with AI agent framework. GraphDB (449ns lookups, 35x faster than RDFox), GraphFrames analytics (PageRank, motifs), Datalog reasoning, HNSW vector embeddings. HyperMindAgent for schema-aware query generation with audit trails. W3C SPARQL 1.1 compliant. Native performance via Rust + NAPI-RS.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",