rust-kgdb 0.6.37 → 0.6.39

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/DESIGN.md ADDED
@@ -0,0 +1,361 @@
1
+ # HyperMind Design Document
2
+
3
+ ## Architecture Overview
4
+
5
+ HyperMind is a neuro-symbolic AI framework that combines LLM planning with deterministic database execution. Unlike traditional AI agents that rely entirely on LLM outputs, HyperMind uses the LLM as a **planner** while executing queries against real data.
6
+
7
+ ```
8
+ ┌─────────────────────────────────────────────────────────────────────────────┐
9
+ │ HYPERMIND ARCHITECTURE │
10
+ ├─────────────────────────────────────────────────────────────────────────────┤
11
+ │ │
12
+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
13
+ │ │ User │ │ Schema │ │ LLM │ │ Typed │ │
14
+ │ │ Query │ -> │ Context │ -> │ Planner │ -> │ Tools │ │
15
+ │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │
16
+ │ │ │ │
17
+ │ │ ▼ │
18
+ │ │ ┌─────────────┐ │
19
+ │ │ │ Database │ │
20
+ │ │ │ Execution │ │
21
+ │ │ └─────────────┘ │
22
+ │ │ │ │
23
+ │ ▼ ▼ │
24
+ │ ┌─────────────────────────────────────────────────┐ │
25
+ │ │ Reasoning Trace │ │
26
+ │ │ (Every step recorded with cryptographic hash) │ │
27
+ │ └─────────────────────────────────────────────────┘ │
28
+ │ │
29
+ └─────────────────────────────────────────────────────────────────────────────┘
30
+ ```
31
+
32
+ ---
33
+
34
+ ## Core Components
35
+
36
+ ### 1. Schema Context (Auto-Extracted)
37
+
38
+ HyperMind automatically extracts schema from your data:
39
+
40
+ ```javascript
41
+ // SchemaContext is a live object, not a string
42
+ SchemaContext = {
43
+ classes: Set(['Professor', 'Student', 'Course', 'Department']),
44
+ properties: Map({
45
+ 'teacherOf': { domain: 'Professor', range: 'Course' },
46
+ 'emailAddress': { domain: 'Person', range: 'string' },
47
+ 'worksFor': { domain: 'Professor', range: 'Department' }
48
+ }),
49
+ aliases: Map({
50
+ 'teacher': 'teacherOf',
51
+ 'email': 'emailAddress',
52
+ 'works_for': 'worksFor'
53
+ })
54
+ }
55
+ ```
56
+
57
+ **Why this matters:** The LLM sees your actual data structure, not a generic prompt.
58
+
59
+ ### 2. Predicate Resolver (Grammar-Based)
60
+
61
+ When LLM generates incorrect predicates, the resolver fixes them:
62
+
63
+ ```
64
+ LLM Output: SELECT ?x WHERE { ?x teacher ?y }
65
+
66
+ Wrong predicate!
67
+
68
+ Resolver Process:
69
+ 1. Parse with pest SPARQL grammar (not regex)
70
+ 2. Extract predicate: "teacher"
71
+ 3. Check schema: "teacher" not found
72
+ 4. Ensemble similarity matching:
73
+ - Jaro-Winkler("teacher", "teacherOf") = 0.89
74
+ - N-gram overlap = 0.75
75
+ - Porter stem match = true
76
+ 5. Resolve: "teacher" → "teacherOf"
77
+
78
+ Fixed Output: SELECT ?x WHERE { ?x teacherOf ?y }
79
+
80
+ Correct predicate!
81
+ ```
82
+
83
+ **Benchmark result:** This adds +14.3 percentage points accuracy (71.4% → 85.7%)
84
+
85
+ ### 3. Typed Tool Registry
86
+
87
+ Every tool has typed input/output signatures:
88
+
89
+ ```javascript
90
+ TOOL_REGISTRY = {
91
+ 'kg.sparql.query': {
92
+ input: 'SPARQLQuery',
93
+ output: 'BindingSet',
94
+ validate: (query) => parseAndValidate(query, schema)
95
+ },
96
+ 'kg.datalog.apply': {
97
+ input: 'DatalogRules',
98
+ output: 'InferredFacts',
99
+ validate: (rules) => checkPredicatesExist(rules, schema)
100
+ },
101
+ 'kg.motif.find': {
102
+ input: 'MotifPattern',
103
+ output: 'MatchSet',
104
+ validate: (pattern) => parseMotifSyntax(pattern)
105
+ }
106
+ }
107
+ ```
108
+
109
+ **Why this matters:** Invalid tool combinations are rejected before execution.
110
+
111
+ ### 4. Reasoning Trace (Audit Trail)
112
+
113
+ Every answer includes a complete derivation:
114
+
115
+ ```javascript
116
+ {
117
+ answer: "Provider PROV-2847 has risk score 0.91",
118
+ reasoningTrace: [
119
+ {
120
+ step: 1,
121
+ tool: "kg.sparql.query",
122
+ input: "SELECT ?p ?s WHERE { ?p :riskScore ?s . FILTER(?s > 0.8) }",
123
+ output: [{ p: "PROV-2847", s: 0.91 }],
124
+ duration: "2.3ms"
125
+ }
126
+ ],
127
+ hash: "sha256:8f3a2b1c4d5e6f7a8b9c0d1e2f3a4b5c"
128
+ }
129
+ ```
130
+
131
+ **Why this matters:** Same question = Same answer = Same hash. Auditable and reproducible.
132
+
133
+ ---
134
+
135
+ ## Mathematical Foundations
136
+
137
+ ### Spivak's Ologs (Category Theory)
138
+
139
+ Schema represented as a category:
140
+ - **Objects** = Classes (Professor, Course, Student)
141
+ - **Morphisms** = Properties (teacherOf, enrolledIn)
142
+ - **Composition** = Property paths (Professor → Course → Department)
143
+
144
+ ```
145
+ Professor ──teacherOf──▶ Course ──offeredBy──▶ Department
146
+ │ │
147
+ └────────────worksFor──────────────────────────┘
148
+ ```
149
+
150
+ ### Metric Space Similarity
151
+
152
+ Predicate resolution uses proper metric space distances:
153
+
154
+ ```
155
+ d(x, y) ≥ 0 (non-negativity)
156
+ d(x, y) = 0 ⟺ x = y (identity)
157
+ d(x, y) = d(y, x) (symmetry)
158
+ d(x, z) ≤ d(x, y) + d(y, z) (triangle inequality)
159
+
160
+ Ensemble similarity combines:
161
+ - Jaro-Winkler distance (character-level)
162
+ - N-gram overlap (substring-level)
163
+ - Jaccard coefficient (token-level)
164
+ - Porter stemming (morphological)
165
+ ```
166
+
167
+ ### Curry-Howard Correspondence
168
+
169
+ Proofs are programs, types are propositions:
170
+
171
+ ```
172
+ Query : SPARQLQuery (type = proposition)
173
+ Result : BindingSet (type = proposition)
174
+ Execution : Query → Result (proof = program)
175
+
176
+ The reasoning trace IS the proof that the answer is correct.
177
+ ```
178
+
179
+ ---
180
+
181
+ ## Benchmark Methodology
182
+
183
+ ### Test Setup
184
+
185
+ - **Dataset:** LUBM (Lehigh University Benchmark)
186
+ - **Size:** 3,272 triples, 30 OWL classes, 23 properties
187
+ - **Model:** GPT-4o
188
+ - **Queries:** 7 natural language questions
189
+ - **Validation:** Regex patterns checking for correct predicates
190
+
191
+ ### Test Queries
192
+
193
+ ```python
194
+ TEST_QUERIES = [
195
+ {"id": "A1", "question": "Find all teachers", "correct": "teacherOf"},
196
+ {"id": "A2", "question": "Get student emails", "correct": "emailAddress"},
197
+ {"id": "A3", "question": "Find faculty members", "correct": "Professor"},
198
+ {"id": "S1", "question": "Count professors"},
199
+ {"id": "S2", "question": "Find graduate students"},
200
+ {"id": "M1", "question": "Find professors who work for departments"},
201
+ {"id": "E1", "question": "Find professors with no publications"}
202
+ ]
203
+ ```
204
+
205
+ ### Results (Verified December 2025)
206
+
207
+ | Stage | Accuracy | Tests Passed | Improvement |
208
+ |-------|----------|--------------|-------------|
209
+ | No Schema | 0-14% | 0-1/7 | Baseline |
210
+ | With Schema | 71.4% | 5/7 | +66.7 pp |
211
+ | With HyperMind | 85.7% | 6/7 | +14.3 pp |
212
+
213
+ **Specific fix:** Query A1 used "teacher" instead of "teacherOf". Predicate resolver corrected this.
214
+
215
+ **Remaining failure:** Query S2 - LLM adds "Here is..." text (formatting issue, not predicate issue).
216
+
217
+ ---
218
+
219
+ ## Comparison with Other Frameworks
220
+
221
+ ### LangChain
222
+
223
+ ```
224
+ Architecture: Prompt Template → LLM → Text Output
225
+ Execution: None (LLM output is final answer)
226
+ Validation: None
227
+ Audit Trail: None
228
+ ```
229
+
230
+ ### DSPy
231
+
232
+ ```
233
+ Architecture: Signature → LLM → Structured Output
234
+ Execution: None (LLM output is final answer)
235
+ Validation: Output structure only
236
+ Audit Trail: None
237
+ ```
238
+
239
+ ### HyperMind
240
+
241
+ ```
242
+ Architecture: Schema → LLM Planner → Typed Tools → Database → Verified Answer
243
+ Execution: Real SPARQL/Datalog on actual data
244
+ Validation: Schema + Type + Predicate resolution
245
+ Audit Trail: Full reasoning trace with hash
246
+ ```
247
+
248
+ ---
249
+
250
+ ## API Reference
251
+
252
+ ### HyperMindAgent
253
+
254
+ ```typescript
255
+ class HyperMindAgent {
256
+ constructor(options: {
257
+ kg: GraphDB, // Your knowledge graph
258
+ model?: string, // 'gpt-4o' | 'claude-3-opus'
259
+ apiKey?: string, // LLM API key
260
+ threshold?: number // Predicate similarity threshold (default: 0.6)
261
+ })
262
+
263
+ async call(prompt: string): Promise<{
264
+ answer: string,
265
+ reasoningTrace: Step[],
266
+ hash: string
267
+ }>
268
+ }
269
+ ```
270
+
271
+ ### OlogSchema
272
+
273
+ ```typescript
274
+ class OlogSchema {
275
+ constructor()
276
+ withNamespace(ns: string): void
277
+ addClass(name: string): void
278
+ addProperty(name: string, domain: string, range: string, aliases?: string[]): void
279
+ build(): void
280
+ hasClass(name: string): boolean
281
+ hasPredicate(name: string): boolean
282
+ }
283
+ ```
284
+
285
+ ### PredicateResolverService
286
+
287
+ ```typescript
288
+ class PredicateResolverService {
289
+ constructor(schema: OlogSchema, threshold?: number)
290
+ resolve(userPredicate: string): string // Returns corrected predicate
291
+ resolveQuery(sparql: string): string // Resolves all predicates in query
292
+ }
293
+ ```
294
+
295
+ ---
296
+
297
+ ## Performance Characteristics
298
+
299
+ | Metric | Value | Notes |
300
+ |--------|-------|-------|
301
+ | Triple Lookup | 2.78 µs | Measured with Criterion |
302
+ | Predicate Resolution | <1 ms | Per predicate |
303
+ | Query Execution | <100 ms | Typical SPARQL query |
304
+ | Memory per Triple | 24 bytes | Best-in-class |
305
+
306
+ ---
307
+
308
+ ## Security Model
309
+
310
+ ### Capability-Based Sandbox
311
+
312
+ ```javascript
313
+ const agent = new HyperMindAgent({
314
+ kg: db,
315
+ sandbox: {
316
+ capabilities: ['ReadKG', 'ExecuteTool'], // No WriteKG = read-only
317
+ fuelLimit: 1_000_000, // CPU budget
318
+ allowedGraphs: ['http://insurance.org/'] // Graph-level access control
319
+ }
320
+ })
321
+ ```
322
+
323
+ ### What's Prevented
324
+
325
+ - SQL injection (typed tools, not string concatenation)
326
+ - Prompt injection (schema limits what can be queried)
327
+ - Runaway execution (fuel metering)
328
+ - Unauthorized access (capability-based)
329
+
330
+ ---
331
+
332
+ ## Limitations
333
+
334
+ 1. **Predicate resolver is not magic:** Only fixes predicates similar to schema terms
335
+ 2. **LLM formatting issues:** Can't fix when LLM adds explanatory text
336
+ 3. **Schema required:** Must have schema to validate against
337
+ 4. **Single database:** Currently supports one knowledge graph per agent
338
+
339
+ ---
340
+
341
+ ## Roadmap
342
+
343
+ - [ ] Multi-database federation
344
+ - [ ] Custom similarity functions
345
+ - [ ] Streaming results
346
+ - [ ] Fine-tuned predicate resolution model
347
+
348
+ ---
349
+
350
+ ## References
351
+
352
+ 1. Spivak, D. (2012). "Ologs: A Categorical Framework for Knowledge Representation"
353
+ 2. Jaro, M. (1989). "Advances in Record-Linkage Methodology"
354
+ 3. Porter, M. (1980). "An Algorithm for Suffix Stripping"
355
+ 4. Curry-Howard Correspondence (1969)
356
+
357
+ ---
358
+
359
+ ## License
360
+
361
+ Apache 2.0
@@ -0,0 +1,404 @@
1
+ # TypeScript SDK Implementation Guide (v0.6.17)
2
+
3
+ ## Plain English Summary
4
+
5
+ **What this SDK does**: Lets you build AI agents that query your data and give verifiable answers.
6
+
7
+ **Key components**:
8
+ - **GraphDB** - Store and query your data (like a database)
9
+ - **HyperMindAgent** - AI that answers questions about your data
10
+ - **Reasoning Trace** - Shows exactly how each answer was derived
11
+
12
+ **Why it matters**: Unlike vanilla LLMs that hallucinate, this gives you answers you can trust and audit.
13
+
14
+ ---
15
+
16
+ ## Overview
17
+
18
+ The TypeScript SDK uses **NAPI-RS** for native Rust bindings with zero-copy performance. Version 0.6.17 includes the complete HyperMind AI framework for building agents that give verifiable answers.
19
+
20
+ ```
21
+ ┌─────────────────────────────────────────────────────────────────────────────┐
22
+ │ ARCHITECTURE OVERVIEW │
23
+ │ │
24
+ │ YOUR APPLICATION (Node.js / TypeScript) │
25
+ │ │ │
26
+ │ ▼ │
27
+ │ ┌───────────────────────────────────────────────────────────────────────┐ │
28
+ │ │ index.js - Entry Point │ │
29
+ │ │ • Platform detection (darwin/linux/win32 × x64/arm64) │ │
30
+ │ │ • Native binding loader │ │
31
+ │ │ • HyperMind framework exports │ │
32
+ │ └───────────────────────────────────────────────────────────────────────┘ │
33
+ │ │ │ │
34
+ │ ▼ ▼ │
35
+ │ ┌─────────────────────┐ ┌─────────────────────────────────────────┐ │
36
+ │ │ Native NAPI-RS │ │ hypermind-agent.js │ │
37
+ │ │ (Rust → Node.js) │ │ (Pure JavaScript Framework) │ │
38
+ │ │ │ │ │ │
39
+ │ │ • GraphDb │ │ • HyperMindAgent │ │
40
+ │ │ • GraphFrame │ │ • LLMPlanner │ │
41
+ │ │ • EmbeddingService │ │ • SchemaAwareGraphDB │ │
42
+ │ │ • DatalogProgram │ │ • SchemaContext │ │
43
+ │ │ • pregelShortestPaths│ │ • MemoryManager │ │
44
+ │ │ │ │ • WasmSandbox │ │
45
+ │ │ ~47MB native addon │ │ • ProofDAG │ │
46
+ │ └─────────────────────┘ └─────────────────────────────────────────┘ │
47
+ │ │
48
+ └─────────────────────────────────────────────────────────────────────────────┘
49
+ ```
50
+
51
+ ## Core Components
52
+
53
+ ### 1. Native NAPI-RS Layer (`native/rust-kgdb-napi/`)
54
+
55
+ **Location**: `native/rust-kgdb-napi/src/lib.rs`
56
+
57
+ The Rust layer provides high-performance database operations:
58
+
59
+ ```rust
60
+ // Core exports
61
+ #[napi]
62
+ pub struct GraphDb { /* ... */ }
63
+
64
+ #[napi]
65
+ impl GraphDb {
66
+ #[napi(constructor)]
67
+ pub fn new(base_uri: String) -> Self { /* ... */ }
68
+
69
+ #[napi]
70
+ pub fn load_ttl(&mut self, ttl: String, graph: Option<String>) -> Result<()> { /* ... */ }
71
+
72
+ #[napi]
73
+ pub fn query_select(&self, sparql: String) -> Result<Vec<QueryResult>> { /* ... */ }
74
+
75
+ #[napi]
76
+ pub fn count_triples(&self) -> Result<u32> { /* ... */ }
77
+ }
78
+ ```
79
+
80
+ **Exported Classes**:
81
+ - `GraphDb` - Core RDF/SPARQL database
82
+ - `GraphFrame` - Graph analytics with DataFusion
83
+ - `EmbeddingService` - Vector similarity with HNSW
84
+ - `DatalogProgram` - Rule-based reasoning
85
+ - `pregelShortestPaths` - Pregel BSP algorithm
86
+
87
+ ### 2. HyperMind Framework Layer (`hypermind-agent.js`)
88
+
89
+ **Location**: `hypermind-agent.js` (~4000 lines)
90
+
91
+ Pure JavaScript implementation of the neuro-symbolic AI framework:
92
+
93
+ ```javascript
94
+ // Key classes and their roles
95
+ class HyperMindAgent {
96
+ constructor({ kg, name, model, scope, memory }) { /* ... */ }
97
+ async call(prompt) { /* Returns ProofDAG-backed response */ }
98
+ }
99
+
100
+ class LLMPlanner {
101
+ constructor(kg, options) { /* ... */ }
102
+ extractSchema() { /* Returns schema as category */ }
103
+ async plan(prompt) { /* Returns typed execution plan */ }
104
+ }
105
+
106
+ class SchemaContext {
107
+ // Auto-extracts your data structure
108
+ // Knows what classes and properties exist
109
+ }
110
+
111
+ class ProofDAG {
112
+ // Records how each answer was derived
113
+ // Includes hash for reproducibility
114
+ }
115
+ ```
116
+
117
+ ### 3. Entry Point (`index.js`)
118
+
119
+ **Location**: `index.js` (~167 lines)
120
+
121
+ Platform detection and unified exports:
122
+
123
+ ```javascript
124
+ function loadNativeBinding() {
125
+ const platform = os.platform() // darwin, linux, win32
126
+ const arch = os.arch() // x64, arm64
127
+
128
+ // Load correct .node file for platform
129
+ if (platform === 'darwin' && arch === 'x64') {
130
+ return require('./rust-kgdb-napi.darwin-x64.node')
131
+ }
132
+ // ... other platforms
133
+ }
134
+
135
+ module.exports = {
136
+ // Native exports
137
+ GraphDB, GraphDb, GraphFrame, EmbeddingService, DatalogProgram,
138
+
139
+ // HyperMind exports
140
+ HyperMindAgent, LLMPlanner, SchemaContext, ProofDAG,
141
+ SchemaAwareGraphDB, MemoryManager, WasmSandbox, AgentScope,
142
+ }
143
+ ```
144
+
145
+ ### 4. Type Definitions (`index.d.ts`)
146
+
147
+ **Location**: `index.d.ts` (~425 lines)
148
+
149
+ Complete TypeScript types for all APIs:
150
+
151
+ ```typescript
152
+ export class GraphDB {
153
+ constructor(baseUri: string)
154
+ loadTtl(ttl: string, graph?: string | null): void
155
+ querySelect(sparql: string): QueryResult[]
156
+ countTriples(): number
157
+ }
158
+
159
+ export class HyperMindAgent {
160
+ constructor(options: HyperMindAgentOptions)
161
+ call(prompt: string): Promise<AgentResponse>
162
+ }
163
+
164
+ export interface ProofDAG {
165
+ root: string
166
+ derivations: Derivation[]
167
+ hash: string
168
+ timestamp: string
169
+ }
170
+ ```
171
+
172
+ ## Technical Foundations
173
+
174
+ > **Plain English**: This section explains WHY HyperMind gives reliable answers. Skip to "Adding New Features" if you just want to use the SDK.
175
+
176
+ ### Schema Awareness (How the system knows your data structure)
177
+
178
+ The SDK automatically extracts your data structure:
179
+ - **Classes** = Types of things in your data (Person, Claim, Provider)
180
+ - **Properties** = Relationships between things (hasName, belongsTo)
181
+ - **Validation** = Ensures queries only reference things that exist
182
+
183
+ ```javascript
184
+ class SchemaContext {
185
+ constructor() {
186
+ this.classes = new Set() // Objects in category
187
+ this.properties = new Map() // Morphisms: predicate → {domain, range}
188
+ }
189
+
190
+ // Functor: Transform between schemas
191
+ static merge(schema1, schema2) { /* ... */ }
192
+
193
+ // Natural transformation: BYOO ontology loading
194
+ static fromOntology(ttl) { /* ... */ }
195
+ }
196
+ ```
197
+
198
+ ### Typed Tools (How tools validate inputs/outputs)
199
+
200
+ Every tool has a defined input and output type:
201
+
202
+ ```javascript
203
+ const TOOL_REGISTRY = {
204
+ 'kg.sparql.query': {
205
+ input: 'Query',
206
+ output: 'BindingSet',
207
+ description: 'Execute SPARQL SELECT query'
208
+ },
209
+ 'kg.datalog.apply': {
210
+ input: 'RuleSet',
211
+ output: 'InferredFacts',
212
+ description: 'Apply Datalog rules'
213
+ },
214
+ 'kg.embeddings.search': {
215
+ input: 'Entity',
216
+ output: 'SimilarEntities',
217
+ description: 'Find semantically similar entities'
218
+ }
219
+ }
220
+
221
+ class TypeId {
222
+ static isCompatible(output, input) {
223
+ // Validates morphism composition
224
+ return typeGraph[output]?.includes(input)
225
+ }
226
+ }
227
+ ```
228
+
229
+ ### Reasoning Trace (How answers are verified)
230
+
231
+ Every answer includes a record of how it was derived:
232
+
233
+ ```javascript
234
+ class ProofDAG {
235
+ constructor() {
236
+ this.nodes = [] // Derivation steps
237
+ this.edges = [] // Dependency links
238
+ this.root = null // Final conclusion
239
+ }
240
+
241
+ addDerivation(tool, input, output, result) {
242
+ // Γ ⊢ tool(input) : output
243
+ this.nodes.push({ tool, input, output, result, timestamp: Date.now() })
244
+ }
245
+
246
+ computeHash() {
247
+ // Deterministic hash for reproducibility
248
+ return crypto.createHash('sha256')
249
+ .update(JSON.stringify(this.nodes))
250
+ .digest('hex')
251
+ }
252
+ }
253
+ ```
254
+
255
+ ## Adding New Features
256
+
257
+ ### Adding a New Native Function
258
+
259
+ 1. **Add Rust implementation** in `native/rust-kgdb-napi/src/lib.rs`:
260
+
261
+ ```rust
262
+ #[napi]
263
+ pub fn my_new_function(arg: String) -> Result<String> {
264
+ // Implementation
265
+ Ok(format!("Result: {}", arg))
266
+ }
267
+ ```
268
+
269
+ 2. **Add TypeScript types** in `index.d.ts`:
270
+
271
+ ```typescript
272
+ export function myNewFunction(arg: string): string
273
+ ```
274
+
275
+ 3. **Export in `index.js`**:
276
+
277
+ ```javascript
278
+ const { myNewFunction } = loadNativeBinding()
279
+ module.exports = { myNewFunction }
280
+ ```
281
+
282
+ 4. **Add tests** in `test-all-features.js`:
283
+
284
+ ```javascript
285
+ test('myNewFunction works correctly', () => {
286
+ const result = myNewFunction('test')
287
+ assert.strictEqual(result, 'Result: test')
288
+ })
289
+ ```
290
+
291
+ ### Adding a New HyperMind Tool
292
+
293
+ 1. **Register in TOOL_REGISTRY** (`hypermind-agent.js`):
294
+
295
+ ```javascript
296
+ const TOOL_REGISTRY = {
297
+ // ... existing tools
298
+ 'kg.custom.myTool': {
299
+ input: 'InputType',
300
+ output: 'OutputType',
301
+ description: 'What this tool does'
302
+ }
303
+ }
304
+ ```
305
+
306
+ 2. **Implement execution** in HyperMindAgent:
307
+
308
+ ```javascript
309
+ async _executeTool(toolName, args) {
310
+ switch (toolName) {
311
+ case 'kg.custom.myTool':
312
+ return this._executeMyTool(args)
313
+ // ... other tools
314
+ }
315
+ }
316
+
317
+ _executeMyTool(args) {
318
+ // Implementation
319
+ return { result: /* ... */ }
320
+ }
321
+ ```
322
+
323
+ 3. **Add to ProofDAG derivation**:
324
+
325
+ ```javascript
326
+ this.proofDAG.addDerivation('kg.custom.myTool', args, result)
327
+ ```
328
+
329
+ ## Testing
330
+
331
+ ### Run All Tests
332
+
333
+ ```bash
334
+ # 42 feature tests
335
+ npm test
336
+
337
+ # 217 Jest tests (includes HyperMind tests)
338
+ npm run test:jest
339
+ ```
340
+
341
+ ### Test Structure
342
+
343
+ ```
344
+ tests/
345
+ ├── regression.test.ts # Core GraphDB tests (28 tests)
346
+ ├── graphframes.test.ts # GraphFrame tests
347
+ ├── embeddings.test.ts # EmbeddingService tests
348
+ ├── datalog.test.ts # Datalog tests
349
+ ├── pregel.test.ts # Pregel tests
350
+ └── hypermind-agent.test.ts # HyperMind framework tests (59 tests)
351
+ ```
352
+
353
+ ## Build Commands
354
+
355
+ ```bash
356
+ # Build native addon (produces .node file)
357
+ npm run build
358
+
359
+ # Build debug version
360
+ npm run build:debug
361
+
362
+ # Under the hood:
363
+ napi build --platform --release native/rust-kgdb-napi
364
+ ```
365
+
366
+ ## Platform Support
367
+
368
+ | Platform | Architecture | File |
369
+ |----------|--------------|------|
370
+ | macOS | Intel (x64) | `rust-kgdb-napi.darwin-x64.node` |
371
+ | macOS | Apple Silicon (arm64) | `rust-kgdb-napi.darwin-arm64.node` |
372
+ | Linux | x64 | `rust-kgdb-napi.linux-x64-gnu.node` |
373
+ | Linux | ARM64 | `rust-kgdb-napi.linux-arm64-gnu.node` |
374
+ | Windows | x64 | `rust-kgdb-napi.win32-x64-msvc.node` |
375
+
376
+ ## Performance Characteristics
377
+
378
+ | Operation | Time | Notes |
379
+ |-----------|------|-------|
380
+ | Triple lookup | 2.78 µs | 35x faster than RDFox |
381
+ | Bulk insert | 146K/sec | Zero-copy semantics |
382
+ | SPARQL query | <100 µs | Cost-based optimizer |
383
+ | Schema extraction | 10-50 ms | Cached 5 minutes |
384
+ | ProofDAG hash | <1 ms | SHA-256 |
385
+
386
+ ## Version History
387
+
388
+ - **v0.6.16**: "Power of Abstraction" introduction, mathematical foundations diagram
389
+ - **v0.6.15**: ProofDAG visualization, LLM evaluation solution, deep dives
390
+ - **v0.6.14**: Industry benchmarks, control plane architecture
391
+ - **v0.6.13**: Schema-Aware GraphDB, Context Theory, BYOO
392
+ - **v0.6.12**: Schema Caching with TTL
393
+ - **v0.6.11**: Context Theory foundation
394
+
395
+ ## Key Files Reference
396
+
397
+ | File | Lines | Purpose |
398
+ |------|-------|---------|
399
+ | `native/rust-kgdb-napi/src/lib.rs` | ~700 | NAPI-RS Rust bindings |
400
+ | `hypermind-agent.js` | ~4050 | HyperMind framework |
401
+ | `index.js` | ~167 | Entry point + loader |
402
+ | `index.d.ts` | ~425 | TypeScript definitions |
403
+ | `test-all-features.js` | ~500 | 42 feature tests |
404
+ | `tests/*.test.ts` | ~2000 | 217 Jest tests |
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rust-kgdb",
3
- "version": "0.6.37",
4
- "description": "Production-grade Neuro-Symbolic AI Framework with Schema-Aware GraphDB, Context Theory, and Memory Hypergraph: +86.4% accuracy over vanilla LLMs. Features Schema-Aware GraphDB (auto schema extraction), BYOO (Bring Your Own Ontology) for enterprise, cross-agent schema caching, LLM Planner for natural language to typed SPARQL, ProofDAG with Curry-Howard witnesses. High-performance (2.78µs lookups, 35x faster than RDFox). W3C SPARQL 1.1 compliant.",
3
+ "version": "0.6.39",
4
+ "description": "Neuro-Symbolic AI Framework: 85.7% accuracy on LUBM benchmark (+14.3pp over schema injection alone). Schema-aware predicate resolution using grammar-based parsing. Features: GraphDB (2.78µs lookups), HyperMindAgent with audit trail, Datalog reasoning, GraphFrames analytics. W3C SPARQL 1.1 compliant.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "napi": {
@@ -85,6 +85,8 @@
85
85
  "ontology/",
86
86
  "README.md",
87
87
  "CLAUDE.md",
88
+ "DESIGN.md",
89
+ "IMPLEMENTATION_GUIDE.md",
88
90
  "HYPERMIND_BENCHMARK_REPORT.md",
89
91
  "CHANGELOG.md",
90
92
  "*.node"