rust-kgdb 0.6.9 → 0.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -68,6 +68,56 @@ const {
|
|
|
68
68
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
69
69
|
// CONFIGURATION - Professional Design Pattern: Configuration Object
|
|
70
70
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
71
|
+
//
|
|
72
|
+
// ┌─────────────────────────────────────────────────────────────────────────────┐
|
|
73
|
+
// │ KNOWLEDGE GRAPH STORAGE MODES │
|
|
74
|
+
// └─────────────────────────────────────────────────────────────────────────────┘
|
|
75
|
+
//
|
|
76
|
+
// MODE 1: IN-MEMORY (Default - Used in this example)
|
|
77
|
+
// ──────────────────────────────────────────────────
|
|
78
|
+
// const db = new GraphDB('http://example.org/') // In-memory, zero config
|
|
79
|
+
// - Storage: RAM only (HashMap-based SPOC indexes)
|
|
80
|
+
// - Performance: 2.78µs lookups, 146K triples/sec insert
|
|
81
|
+
// - Persistence: None (data lost on restart)
|
|
82
|
+
// - Use case: Development, testing, ephemeral workloads
|
|
83
|
+
//
|
|
84
|
+
// MODE 2: ENDPOINT (Distributed Cluster)
|
|
85
|
+
// ──────────────────────────────────────
|
|
86
|
+
// const agent = await HyperMindAgent.spawn({
|
|
87
|
+
// endpoint: 'http://rust-kgdb-coordinator:8080', // K8s service
|
|
88
|
+
// ...
|
|
89
|
+
// })
|
|
90
|
+
// - Storage: HDRF-partitioned across executors
|
|
91
|
+
// - Persistence: RocksDB/LMDB per executor
|
|
92
|
+
// - Consensus: Raft for distributed writes
|
|
93
|
+
// - Use case: Production, 1B+ triples
|
|
94
|
+
//
|
|
95
|
+
// ┌─────────────────────────────────────────────────────────────────────────────┐
|
|
96
|
+
// │ DEFAULT SETTINGS (When not specified) │
|
|
97
|
+
// └─────────────────────────────────────────────────────────────────────────────┘
|
|
98
|
+
//
|
|
99
|
+
// KG Defaults:
|
|
100
|
+
// storage: 'inmemory' // Not 'rocksdb' or 'lmdb'
|
|
101
|
+
// endpoint: null // Local mode, no network
|
|
102
|
+
// graphUri: null // Default graph (not named graph)
|
|
103
|
+
//
|
|
104
|
+
// Memory Layer Defaults:
|
|
105
|
+
// working.maxSize: 1MB // Current task context
|
|
106
|
+
// episodic.retentionDays: 30 // Conversation history
|
|
107
|
+
// longTerm: db // KG as long-term memory (same instance!)
|
|
108
|
+
// weights: { recency: 0.3, relevance: 0.5, importance: 0.2 }
|
|
109
|
+
//
|
|
110
|
+
// Sandbox Defaults (when .withSandbox() NOT called):
|
|
111
|
+
// sandbox: null // NO SANDBOX - full access to all tools
|
|
112
|
+
// ⚠️ WARNING: Without sandbox, agent has unrestricted capabilities
|
|
113
|
+
// ⚠️ Always use .withSandbox() in production for security
|
|
114
|
+
//
|
|
115
|
+
// Governance Defaults:
|
|
116
|
+
// maxExecutionTimeMs: 60000 // 60 second timeout
|
|
117
|
+
// maxToolCalls: 100 // Rate limiting
|
|
118
|
+
// auditLevel: 'basic' // Not 'full'
|
|
119
|
+
//
|
|
120
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
71
121
|
|
|
72
122
|
const CONFIG = {
|
|
73
123
|
// LLM Configuration
|
|
@@ -79,15 +129,48 @@ const CONFIG = {
|
|
|
79
129
|
},
|
|
80
130
|
|
|
81
131
|
// Knowledge Graph Configuration
|
|
132
|
+
// ─────────────────────────────
|
|
133
|
+
// This example uses IN-MEMORY mode for simplicity.
|
|
134
|
+
// For production, use endpoint mode with distributed cluster.
|
|
82
135
|
kg: {
|
|
136
|
+
// Storage mode: 'inmemory' (default) | 'rocksdb' | 'lmdb' | 'endpoint'
|
|
137
|
+
storage: 'inmemory',
|
|
138
|
+
|
|
139
|
+
// Base URI for all entities (required)
|
|
83
140
|
baseUri: 'http://insurance.org/fraud-detection',
|
|
84
|
-
|
|
141
|
+
|
|
142
|
+
// Named graph URI (optional, null = default graph)
|
|
143
|
+
graphUri: 'http://insurance.org/fraud-kb',
|
|
144
|
+
|
|
145
|
+
// Endpoint for distributed mode (null = local mode)
|
|
146
|
+
// endpoint: 'http://rust-kgdb-coordinator:8080', // Uncomment for cluster
|
|
147
|
+
endpoint: null
|
|
85
148
|
},
|
|
86
149
|
|
|
87
150
|
// Embedding Configuration (384-dim for compatibility)
|
|
88
151
|
embeddings: {
|
|
89
152
|
dimensions: 384,
|
|
90
|
-
similarityThreshold: 0.7
|
|
153
|
+
similarityThreshold: 0.7,
|
|
154
|
+
// Provider: 'mock' (default) | 'openai' | 'ollama' | 'anthropic'
|
|
155
|
+
provider: 'mock'
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
// Memory Layer Configuration (v0.5.13+)
|
|
159
|
+
// ─────────────────────────────────────
|
|
160
|
+
memory: {
|
|
161
|
+
working: {
|
|
162
|
+
maxSize: 1024 * 1024 // 1MB working memory for current task
|
|
163
|
+
},
|
|
164
|
+
episodic: {
|
|
165
|
+
retentionDays: 30, // Keep 30 days of conversation history
|
|
166
|
+
maxEpisodes: 1000 // Cap total episodes
|
|
167
|
+
},
|
|
168
|
+
// longTerm: db // Set after db initialization (uses same KG!)
|
|
169
|
+
weights: {
|
|
170
|
+
recency: 0.3, // How recent (0.995^hours decay)
|
|
171
|
+
relevance: 0.5, // Semantic similarity to query
|
|
172
|
+
importance: 0.2 // Access frequency
|
|
173
|
+
}
|
|
91
174
|
},
|
|
92
175
|
|
|
93
176
|
// Agent Configuration
|
|
@@ -96,6 +179,19 @@ const CONFIG = {
|
|
|
96
179
|
tools: ['kg.sparql.query', 'kg.motif.find', 'kg.datalog.apply', 'kg.embeddings.search'],
|
|
97
180
|
maxIterations: 10,
|
|
98
181
|
tracingEnabled: true
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
// Sandbox Configuration (v0.6.7+)
|
|
185
|
+
// ────────────────────────────────
|
|
186
|
+
// ⚠️ IMPORTANT: If sandbox is null/undefined, agent has FULL ACCESS
|
|
187
|
+
// Always define sandbox in production for capability-based security
|
|
188
|
+
sandbox: {
|
|
189
|
+
capabilities: ['ReadKG', 'WriteKG', 'ExecuteTool', 'UseEmbeddings'],
|
|
190
|
+
fuelLimit: 1_000_000, // Gas limit (prevents infinite loops)
|
|
191
|
+
maxExecTime: 30_000, // 30 second timeout
|
|
192
|
+
maxMemory: 64 * 1024 * 1024, // 64MB memory limit
|
|
193
|
+
allowedNamespaces: ['http://insurance.org/'],
|
|
194
|
+
auditLevel: 'full' // 'none' | 'basic' | 'full'
|
|
99
195
|
}
|
|
100
196
|
}
|
|
101
197
|
|
|
@@ -321,18 +417,44 @@ async function main() {
|
|
|
321
417
|
// ───────────────────────────────────────────────────────────────────────────
|
|
322
418
|
// PHASE 1: Initialize Knowledge Graph
|
|
323
419
|
// ───────────────────────────────────────────────────────────────────────────
|
|
420
|
+
//
|
|
421
|
+
// KG Storage Modes:
|
|
422
|
+
// ─────────────────
|
|
423
|
+
// 1. IN-MEMORY (this example):
|
|
424
|
+
// const db = new GraphDB(baseUri) // No config = in-memory
|
|
425
|
+
//
|
|
426
|
+
// 2. PERSISTENT (RocksDB):
|
|
427
|
+
// const db = new GraphDB(baseUri, { storage: 'rocksdb', path: '/data/kg' })
|
|
428
|
+
//
|
|
429
|
+
// 3. DISTRIBUTED (Cluster endpoint):
|
|
430
|
+
// const agent = await HyperMindAgent.spawn({
|
|
431
|
+
// endpoint: 'http://rust-kgdb-coordinator:8080',
|
|
432
|
+
// name: 'fraud-detector',
|
|
433
|
+
// ...
|
|
434
|
+
// })
|
|
435
|
+
// // Agent handles KG operations via gRPC to cluster
|
|
436
|
+
//
|
|
437
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
324
438
|
|
|
325
439
|
console.log('┌─ PHASE 1: Knowledge Graph Initialization ───────────────────────────────┐')
|
|
326
|
-
console.log('│
|
|
327
|
-
console.log('│
|
|
440
|
+
console.log('│ Mode: IN-MEMORY (HashMap-based SPOC indexes) │')
|
|
441
|
+
console.log('│ Performance: 2.78µs lookups | 24 bytes/triple | Zero-copy │')
|
|
328
442
|
console.log('└─────────────────────────────────────────────────────────────────────────┘')
|
|
329
443
|
|
|
444
|
+
// Initialize KG - IN-MEMORY mode (default when no storage config provided)
|
|
445
|
+
// For production with persistence: new GraphDB(baseUri, { storage: 'rocksdb', path: '/data' })
|
|
330
446
|
const db = new GraphDB(CONFIG.kg.baseUri)
|
|
447
|
+
|
|
448
|
+
// Load TTL data into named graph
|
|
449
|
+
// null = default graph, string = named graph URI
|
|
331
450
|
db.loadTtl(FRAUD_ONTOLOGY, CONFIG.kg.graphUri)
|
|
332
451
|
const tripleCount = db.countTriples()
|
|
333
452
|
|
|
334
|
-
console.log(` ✓
|
|
453
|
+
console.log(` ✓ Storage Mode: ${CONFIG.kg.storage} (data in RAM, lost on restart)`)
|
|
454
|
+
console.log(` ✓ Base URI: ${CONFIG.kg.baseUri}`)
|
|
335
455
|
console.log(` ✓ Graph URI: ${CONFIG.kg.graphUri}`)
|
|
456
|
+
console.log(` ✓ Triples Loaded: ${tripleCount}`)
|
|
457
|
+
console.log(` ✓ Endpoint: ${CONFIG.kg.endpoint || 'null (local mode, no network)'}`)
|
|
336
458
|
console.log()
|
|
337
459
|
|
|
338
460
|
// ───────────────────────────────────────────────────────────────────────────
|
|
@@ -62,6 +62,56 @@ const {
|
|
|
62
62
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
63
63
|
// CONFIGURATION
|
|
64
64
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
65
|
+
//
|
|
66
|
+
// ┌─────────────────────────────────────────────────────────────────────────────┐
|
|
67
|
+
// │ KNOWLEDGE GRAPH STORAGE MODES │
|
|
68
|
+
// └─────────────────────────────────────────────────────────────────────────────┘
|
|
69
|
+
//
|
|
70
|
+
// MODE 1: IN-MEMORY (Default - Used in this example)
|
|
71
|
+
// ──────────────────────────────────────────────────
|
|
72
|
+
// const db = new GraphDB('http://example.org/') // In-memory, zero config
|
|
73
|
+
// - Storage: RAM only (HashMap-based SPOC indexes)
|
|
74
|
+
// - Performance: 2.78µs lookups, 146K triples/sec insert
|
|
75
|
+
// - Persistence: None (data lost on restart)
|
|
76
|
+
// - Use case: Development, testing, ephemeral workloads
|
|
77
|
+
//
|
|
78
|
+
// MODE 2: ENDPOINT (Distributed Cluster)
|
|
79
|
+
// ──────────────────────────────────────
|
|
80
|
+
// const agent = await HyperMindAgent.spawn({
|
|
81
|
+
// endpoint: 'http://rust-kgdb-coordinator:8080', // K8s service
|
|
82
|
+
// ...
|
|
83
|
+
// })
|
|
84
|
+
// - Storage: HDRF-partitioned across executors
|
|
85
|
+
// - Persistence: RocksDB/LMDB per executor
|
|
86
|
+
// - Consensus: Raft for distributed writes
|
|
87
|
+
// - Use case: Production, 1B+ triples
|
|
88
|
+
//
|
|
89
|
+
// ┌─────────────────────────────────────────────────────────────────────────────┐
|
|
90
|
+
// │ DEFAULT SETTINGS (When not specified) │
|
|
91
|
+
// └─────────────────────────────────────────────────────────────────────────────┘
|
|
92
|
+
//
|
|
93
|
+
// KG Defaults:
|
|
94
|
+
// storage: 'inmemory' // Not 'rocksdb' or 'lmdb'
|
|
95
|
+
// endpoint: null // Local mode, no network
|
|
96
|
+
// graphUri: null // Default graph (not named graph)
|
|
97
|
+
//
|
|
98
|
+
// Memory Layer Defaults:
|
|
99
|
+
// working.maxSize: 1MB // Current task context
|
|
100
|
+
// episodic.retentionDays: 30 // Conversation history
|
|
101
|
+
// longTerm: db // KG as long-term memory (same instance!)
|
|
102
|
+
// weights: { recency: 0.3, relevance: 0.5, importance: 0.2 }
|
|
103
|
+
//
|
|
104
|
+
// Sandbox Defaults (when .withSandbox() NOT called):
|
|
105
|
+
// sandbox: null // NO SANDBOX - full access to all tools
|
|
106
|
+
// ⚠️ WARNING: Without sandbox, agent has unrestricted capabilities
|
|
107
|
+
// ⚠️ Always use .withSandbox() in production for security
|
|
108
|
+
//
|
|
109
|
+
// Governance Defaults:
|
|
110
|
+
// maxExecutionTimeMs: 60000 // 60 second timeout
|
|
111
|
+
// maxToolCalls: 100 // Rate limiting
|
|
112
|
+
// auditLevel: 'basic' // Not 'full'
|
|
113
|
+
//
|
|
114
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
65
115
|
|
|
66
116
|
const MODEL = process.argv.includes('--model')
|
|
67
117
|
? process.argv[process.argv.indexOf('--model') + 1]
|
|
@@ -69,6 +119,51 @@ const MODEL = process.argv.includes('--model')
|
|
|
69
119
|
: process.env.OPENAI_API_KEY ? 'gpt-4o'
|
|
70
120
|
: 'mock'
|
|
71
121
|
|
|
122
|
+
// Full configuration object with all settings
|
|
123
|
+
const CONFIG = {
|
|
124
|
+
// LLM Configuration
|
|
125
|
+
llm: {
|
|
126
|
+
model: MODEL,
|
|
127
|
+
maxTokens: 1024,
|
|
128
|
+
temperature: 0.1
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
// Knowledge Graph Configuration
|
|
132
|
+
// ─────────────────────────────
|
|
133
|
+
// This example uses IN-MEMORY mode for simplicity.
|
|
134
|
+
// For production, use endpoint mode with distributed cluster.
|
|
135
|
+
kg: {
|
|
136
|
+
storage: 'inmemory', // 'inmemory' | 'rocksdb' | 'lmdb' | 'endpoint'
|
|
137
|
+
baseUri: 'http://underwriting.org/',
|
|
138
|
+
graphUri: 'http://underwriting.org/kb',
|
|
139
|
+
endpoint: null // Set to cluster URL for distributed mode
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
// Embedding Configuration
|
|
143
|
+
embeddings: {
|
|
144
|
+
dimensions: 384,
|
|
145
|
+
similarityThreshold: 0.7,
|
|
146
|
+
provider: 'mock' // 'mock' | 'openai' | 'ollama' | 'anthropic'
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
// Memory Layer Configuration (v0.5.13+)
|
|
150
|
+
memory: {
|
|
151
|
+
working: { maxSize: 1024 * 1024 }, // 1MB
|
|
152
|
+
episodic: { retentionDays: 30, maxEpisodes: 1000 },
|
|
153
|
+
weights: { recency: 0.3, relevance: 0.5, importance: 0.2 }
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
// Sandbox Configuration (v0.6.7+)
|
|
157
|
+
// ⚠️ If null, agent has FULL ACCESS - always set in production
|
|
158
|
+
sandbox: {
|
|
159
|
+
capabilities: ['ReadKG', 'ExecuteTool', 'UseEmbeddings', 'AccessMemory'],
|
|
160
|
+
fuelLimit: 500_000,
|
|
161
|
+
maxExecTime: 30_000,
|
|
162
|
+
maxMemory: 64 * 1024 * 1024,
|
|
163
|
+
auditLevel: 'full'
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
72
167
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
73
168
|
// UNDERWRITING KNOWLEDGE BASE (ISO/NAIC-Informed Data)
|
|
74
169
|
// ═══════════════════════════════════════════════════════════════════════════
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rust-kgdb",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
4
4
|
"description": "Production-grade Neuro-Symbolic AI Framework with Memory Hypergraph: +86.4% accuracy improvement over vanilla LLMs. High-performance knowledge graph (2.78µs lookups, 35x faster than RDFox). Features Memory Hypergraph (temporal scoring, rolling context window, idempotent responses), fraud detection, underwriting agents, WASM sandbox, type/category/proof theory, and W3C SPARQL 1.1 compliance.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|