rust-kgdb 0.8.12 → 0.8.13
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/CHANGELOG.md +55 -0
- package/README.md +55 -0
- package/hypermind-agent.js +65 -4
- package/index.d.ts +116 -0
- package/package.json +1 -1
- package/rust-kgdb-napi.darwin-x64.node +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,61 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to the rust-kgdb TypeScript SDK will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.8.13] - 2025-12-22
|
|
6
|
+
|
|
7
|
+
### 100% Verified Euroleague Example with Real Output
|
|
8
|
+
|
|
9
|
+
This release certifies **100% test pass rate** on the Euroleague basketball example with actual SPARQL output, deductive reasoning, and cryptographic proofs.
|
|
10
|
+
|
|
11
|
+
#### What's New
|
|
12
|
+
|
|
13
|
+
| Feature | Description | Evidence |
|
|
14
|
+
|---------|-------------|----------|
|
|
15
|
+
| **ThinkingReasoner** | Deductive reasoning with proofs | 111 observations → 222 derived facts |
|
|
16
|
+
| **RDF2Vec Embeddings** | In-memory graph embeddings | 138 entities, 128D, 1380 walks in 2.4s |
|
|
17
|
+
| **Prompt Optimization** | Schema extraction for LLM context | 11 classes, 7 predicates auto-extracted |
|
|
18
|
+
| **OWL Reasoning** | SymmetricProperty + TransitiveProperty | Zero hallucination - only provable facts |
|
|
19
|
+
| **Derivation Chain** | Step-by-step proof traces | SHA-256 hash per derivation |
|
|
20
|
+
|
|
21
|
+
#### Verified Test Results (Euroleague Example)
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
SPARQL Queries with Assertions:
|
|
25
|
+
[PASS] Teams count = 2 (BER, PAN)
|
|
26
|
+
[PASS] Players count = 22
|
|
27
|
+
[PASS] Steals count = 3 (Lessort, Mitoglou, Mattisseck)
|
|
28
|
+
[PASS] Assist events count = 8
|
|
29
|
+
[PASS] Teammate links = 111
|
|
30
|
+
|
|
31
|
+
ThinkingReasoner with Deductive Reasoning:
|
|
32
|
+
Observations: 111
|
|
33
|
+
Derived Facts: 222
|
|
34
|
+
Rules Applied: 2 (SymmetricProperty + TransitiveProperty)
|
|
35
|
+
|
|
36
|
+
Use Case Queries:
|
|
37
|
+
JOURNALIST: "Who made steals?" → 3 results [PASS]
|
|
38
|
+
COACH: "Who had assists?" → 8 results [PASS]
|
|
39
|
+
ANALYST: "Scoring plays?" → 26 results [PASS]
|
|
40
|
+
FAN: "Lessort's teammates?" → 8 results [PASS]
|
|
41
|
+
|
|
42
|
+
TEST RESULTS: 17 PASSED, 0 FAILED - 100.0% PASS RATE
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
#### Working Examples Repository
|
|
46
|
+
|
|
47
|
+
See all examples running: [hypermind-examples](https://github.com/gonnect-uk/hypermind-examples)
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
git clone https://github.com/gonnect-uk/hypermind-examples.git
|
|
51
|
+
cd hypermind-examples
|
|
52
|
+
npm install
|
|
53
|
+
npm run euroleague # 100% pass rate
|
|
54
|
+
npm run fraud # Circular payment detection
|
|
55
|
+
npm run federation # KGDB + Snowflake + BigQuery
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
5
60
|
## [0.8.6] - 2025-12-21
|
|
6
61
|
|
|
7
62
|
### ThinkingReasoner: Verified Rust Core Demo
|
package/README.md
CHANGED
|
@@ -37,6 +37,61 @@ node node_modules/rust-kgdb/examples/fraud-underwriting-reallife-demo.js
|
|
|
37
37
|
|
|
38
38
|
---
|
|
39
39
|
|
|
40
|
+
## What's New in v0.8.13
|
|
41
|
+
|
|
42
|
+
**100% Verified. 100% Deterministic. 100% Honest.**
|
|
43
|
+
|
|
44
|
+
We just shipped the most rigorous AI framework you'll find anywhere. Every query returns **actual SPARQL**, every conclusion has a **cryptographic proof**, and we have **17/17 tests passing** on real-world data.
|
|
45
|
+
|
|
46
|
+
| Feature | What It Does | The Proof |
|
|
47
|
+
|---------|--------------|-----------|
|
|
48
|
+
| **ThinkingReasoner** | Deductive engine that SHOWS ITS WORK | 111 observations → 222 derived facts |
|
|
49
|
+
| **RDF2Vec Embeddings** | Graph embeddings trained IN-MEMORY | 138 entities, 128D, 1380 random walks in 2.4s |
|
|
50
|
+
| **Prompt Optimization** | Auto-extracts schema for LLM context | 11 classes, 7 predicates from data |
|
|
51
|
+
| **OWL Reasoning** | SymmetricProperty + TransitiveProperty rules | Zero hallucination - only provable facts |
|
|
52
|
+
| **Derivation Chain** | Step-by-step proof like showing math work | SHA-256 hash per derivation |
|
|
53
|
+
|
|
54
|
+
### Real Output, Not Marketing Speak
|
|
55
|
+
|
|
56
|
+
**See it running:** [hypermind-examples](https://github.com/gonnect-uk/hypermind-examples)
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
git clone https://github.com/gonnect-uk/hypermind-examples.git
|
|
60
|
+
cd hypermind-examples
|
|
61
|
+
npm install
|
|
62
|
+
npm run euroleague
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Actual output from `npm run euroleague`:**
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
[5] ThinkingReasoner with Deductive Reasoning:
|
|
69
|
+
Observations: 111
|
|
70
|
+
Derived Facts: 222
|
|
71
|
+
Rules Applied: 2
|
|
72
|
+
[PASS] Derived facts = 222 (symmetric property doubles links)
|
|
73
|
+
|
|
74
|
+
[6] Thinking Graph (Derivation Chain / Proofs):
|
|
75
|
+
Step 1: [OBSERVATION] grant__jerian teammateOf osman__cedi
|
|
76
|
+
Step 2: [OBSERVATION] brown__lorenzo teammateOf osman__cedi
|
|
77
|
+
...
|
|
78
|
+
Step 8: [OBSERVATION] hernangomez__juancho teammateOf osman__cedi
|
|
79
|
+
|
|
80
|
+
JOURNALIST: "Who made the defensive steals?"
|
|
81
|
+
SPARQL: SELECT ?player WHERE {
|
|
82
|
+
?e rdf:type euro:Steal .
|
|
83
|
+
?e euro:player ?player .
|
|
84
|
+
}
|
|
85
|
+
RESULTS: 3 bindings (lessort, mitoglou, mattisseck)
|
|
86
|
+
[PASS] JOURNALIST: Who made the defensive steals?
|
|
87
|
+
|
|
88
|
+
TEST RESULTS: 17 PASSED, 0 FAILED - 100.0% PASS RATE
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
That's **real SPARQL**, **real results**, **real proofs**. No mocking. No hardcoding. Just `npm install` and it works.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
40
95
|
## What's New in v0.8.7
|
|
41
96
|
|
|
42
97
|
**What if every AI conclusion came with a mathematical proof?**
|
package/hypermind-agent.js
CHANGED
|
@@ -3281,16 +3281,19 @@ Intent types: detect_fraud, find_similar, explain, find_patterns, aggregate, gen
|
|
|
3281
3281
|
if (context.sparql) return context.sparql
|
|
3282
3282
|
|
|
3283
3283
|
const predicates = schema.predicates || []
|
|
3284
|
+
const classes = schema.classes || []
|
|
3284
3285
|
const prompt = context.originalPrompt || ''
|
|
3286
|
+
const promptLower = prompt.toLowerCase()
|
|
3285
3287
|
|
|
3286
3288
|
// Aggregate queries don't need specific predicates
|
|
3287
3289
|
if (intent.aggregate) {
|
|
3288
3290
|
return 'SELECT (COUNT(*) as ?count) WHERE { ?s ?p ?o }'
|
|
3289
3291
|
}
|
|
3290
3292
|
|
|
3291
|
-
//
|
|
3293
|
+
// STEP 1: Match prompt against PREDICATES FIRST (higher priority for relationships)
|
|
3294
|
+
// This handles queries like "teammates of X" -> teammateOf predicate
|
|
3292
3295
|
const rankedPreds = this._findRelevantPredicatesRanked
|
|
3293
|
-
? this._findRelevantPredicatesRanked(
|
|
3296
|
+
? this._findRelevantPredicatesRanked(promptLower, predicates, { threshold: 0.3 })
|
|
3294
3297
|
: []
|
|
3295
3298
|
|
|
3296
3299
|
// If we have high-confidence predicate matches, use them
|
|
@@ -3309,7 +3312,33 @@ Intent types: detect_fraud, find_similar, explain, find_patterns, aggregate, gen
|
|
|
3309
3312
|
return `SELECT ?s ?o WHERE { ?s <${bestPred.predicate}> ?o } LIMIT ${CONFIG.query.defaultLimit}`
|
|
3310
3313
|
}
|
|
3311
3314
|
|
|
3312
|
-
//
|
|
3315
|
+
// STEP 2: Match prompt against CLASSES (for event types like Steal, Assist)
|
|
3316
|
+
// Only after predicate matching fails, check for type-filtered queries
|
|
3317
|
+
const rankedClasses = this._findRelevantPredicatesRanked
|
|
3318
|
+
? this._findRelevantPredicatesRanked(promptLower, classes, { threshold: 0.4 })
|
|
3319
|
+
: []
|
|
3320
|
+
|
|
3321
|
+
// If we have a class match, generate a type-filtered query
|
|
3322
|
+
if (rankedClasses.length > 0 && rankedClasses[0].score >= 0.5) {
|
|
3323
|
+
const matchedClass = rankedClasses[0]
|
|
3324
|
+
|
|
3325
|
+
// Look for a "player" or "agent" predicate to link events to entities
|
|
3326
|
+
const playerPred = predicates.find(p =>
|
|
3327
|
+
p.toLowerCase().includes('player') ||
|
|
3328
|
+
p.toLowerCase().includes('agent') ||
|
|
3329
|
+
p.toLowerCase().includes('actor')
|
|
3330
|
+
)
|
|
3331
|
+
|
|
3332
|
+
if (playerPred) {
|
|
3333
|
+
// Generate query like: SELECT ?player WHERE { ?event a :Steal . ?event :player ?player }
|
|
3334
|
+
return `SELECT ?entity WHERE { ?event a <${matchedClass.predicate}> . ?event <${playerPred}> ?entity } LIMIT ${CONFIG.query.defaultLimit}`
|
|
3335
|
+
} else {
|
|
3336
|
+
// Just get entities of this type
|
|
3337
|
+
return `SELECT ?entity WHERE { ?entity a <${matchedClass.predicate}> } LIMIT ${CONFIG.query.defaultLimit}`
|
|
3338
|
+
}
|
|
3339
|
+
}
|
|
3340
|
+
|
|
3341
|
+
// STEP 3: If we have type-related predicates, use for general class queries
|
|
3313
3342
|
if (intent.query || intent.compliance) {
|
|
3314
3343
|
const typePredsRanked = this._findRelevantPredicatesRanked
|
|
3315
3344
|
? this._findRelevantPredicatesRanked('type class', predicates, { threshold: 0.4 })
|
|
@@ -5299,8 +5328,40 @@ class HyperMindAgent {
|
|
|
5299
5328
|
|
|
5300
5329
|
_generateToolArgs(tool, intent, prompt) {
|
|
5301
5330
|
switch (tool) {
|
|
5302
|
-
case 'kg.sparql.query':
|
|
5331
|
+
case 'kg.sparql.query': {
|
|
5332
|
+
// Use schema-aware SPARQL generation if schema API is available
|
|
5333
|
+
let schema = { predicates: [], classes: [] }
|
|
5334
|
+
if (this.kg && typeof this.kg.getSchema === 'function') {
|
|
5335
|
+
try {
|
|
5336
|
+
const schemaJson = this.kg.getSchema()
|
|
5337
|
+
const parsed = JSON.parse(schemaJson)
|
|
5338
|
+
schema = {
|
|
5339
|
+
predicates: parsed.predicates || [],
|
|
5340
|
+
classes: parsed.classes || []
|
|
5341
|
+
}
|
|
5342
|
+
} catch (e) {
|
|
5343
|
+
// Schema not available - fall back to default
|
|
5344
|
+
}
|
|
5345
|
+
}
|
|
5346
|
+
|
|
5347
|
+
// If we have schema, use schema-aware generation via LLMPlanner
|
|
5348
|
+
if (schema.predicates.length > 0 && this.planner) {
|
|
5349
|
+
const context = { originalPrompt: prompt }
|
|
5350
|
+
const sparql = this.planner._generateSchemaSparql(intent, schema, context)
|
|
5351
|
+
|
|
5352
|
+
// Validate the generated SPARQL against schema using planner's validator
|
|
5353
|
+
const validation = this.planner._validateQueryPredicates(sparql, schema)
|
|
5354
|
+
if (validation.warnings.length > 0) {
|
|
5355
|
+
// Log validation warning but proceed
|
|
5356
|
+
console.warn('[HyperMindAgent] SPARQL validation warning:', validation.warnings.map(w => w.message))
|
|
5357
|
+
}
|
|
5358
|
+
|
|
5359
|
+
return { query: sparql }
|
|
5360
|
+
}
|
|
5361
|
+
|
|
5362
|
+
// Fall back to hardcoded templates if no schema
|
|
5303
5363
|
return { query: this._generateSparql(intent, prompt) }
|
|
5364
|
+
}
|
|
5304
5365
|
case 'kg.datalog.infer':
|
|
5305
5366
|
return { rules: this._selectRules(intent) }
|
|
5306
5367
|
case 'kg.embeddings.search':
|
package/index.d.ts
CHANGED
|
@@ -71,6 +71,122 @@ export class GraphDB {
|
|
|
71
71
|
* Get app graph URI
|
|
72
72
|
*/
|
|
73
73
|
getGraphUri(): string
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get extracted schema as JSON string
|
|
77
|
+
* Contains classes, predicates, OWL properties from W3C patterns
|
|
78
|
+
*/
|
|
79
|
+
getSchema(): string
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Wait for schema to be ready
|
|
83
|
+
* @returns true when schema is extracted
|
|
84
|
+
*/
|
|
85
|
+
waitForSchema(): boolean
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Get schema statistics
|
|
89
|
+
*/
|
|
90
|
+
getSchemaStats(): string
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Validate SPARQL query predicates against loaded schema
|
|
94
|
+
* @param sparql - SPARQL query to validate
|
|
95
|
+
* @returns JSON with validation results
|
|
96
|
+
*/
|
|
97
|
+
validateSparql(sparql: string): string
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Load TTL with automatic RDF2Vec embedding generation
|
|
101
|
+
*
|
|
102
|
+
* This is the recommended way to load data for HyperMindAgent:
|
|
103
|
+
* 1. Loads TTL data
|
|
104
|
+
* 2. Extracts schema from W3C patterns
|
|
105
|
+
* 3. Generates random walks over the graph
|
|
106
|
+
* 4. Trains Word2Vec embeddings
|
|
107
|
+
* 5. Stores embeddings for similarity search
|
|
108
|
+
*
|
|
109
|
+
* @param ttlContent - Turtle format RDF data
|
|
110
|
+
* @param graphName - Optional named graph URI
|
|
111
|
+
* @param embeddingConfig - Optional embedding configuration
|
|
112
|
+
* @returns JSON string with load stats including embedding info
|
|
113
|
+
*/
|
|
114
|
+
loadTtlWithEmbeddings(ttlContent: string, graphName: string | null, embeddingConfig?: EmbeddingConfig | null): string
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get embedding vector for an entity
|
|
118
|
+
* @param entity - Entity URI
|
|
119
|
+
* @returns Vector as array of f64, or null if not found
|
|
120
|
+
*/
|
|
121
|
+
getEmbedding(entity: string): number[] | null
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Find similar entities using cosine similarity
|
|
125
|
+
* @param entity - Query entity URI
|
|
126
|
+
* @param k - Number of similar entities to return
|
|
127
|
+
* @returns JSON array of {entity, similarity} objects
|
|
128
|
+
*/
|
|
129
|
+
findSimilar(entity: string, k: number): string
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Check if embeddings are trained and available
|
|
133
|
+
*/
|
|
134
|
+
hasEmbeddings(): boolean
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Get embedding statistics
|
|
138
|
+
*/
|
|
139
|
+
getEmbeddingStats(): string
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Build HyperFederate SQL-first prompt with dynamic schema context
|
|
143
|
+
*
|
|
144
|
+
* Takes a user prompt and returns the full LLM system prompt with:
|
|
145
|
+
* - HyperFederate SQL grammar and graph_search() UDF documentation
|
|
146
|
+
* - Available schema elements (classes, predicates) from loaded data
|
|
147
|
+
* - Statistics (triple count, class count, predicate count)
|
|
148
|
+
* - Rules to prevent hallucination
|
|
149
|
+
*
|
|
150
|
+
* @param userPrompt - The user's natural language question
|
|
151
|
+
* @returns Full system prompt for LLM with schema context injected
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* const db = new GraphDB('http://example.org/')
|
|
156
|
+
* db.loadTtl(ttlData, null)
|
|
157
|
+
*
|
|
158
|
+
* // Generate prompt with schema context
|
|
159
|
+
* const systemPrompt = db.buildSqlPrompt('Who made steals?')
|
|
160
|
+
*
|
|
161
|
+
* // Send to LLM
|
|
162
|
+
* const response = await llm.chat({
|
|
163
|
+
* messages: [{ role: 'system', content: systemPrompt }]
|
|
164
|
+
* })
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
buildSqlPrompt(userPrompt: string): string
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Generate random walks from loaded graph data
|
|
171
|
+
* @param walksPerNode - Number of walks per entity (default: 10)
|
|
172
|
+
* @param walkLength - Maximum walk length (default: 5)
|
|
173
|
+
* @returns JSON array of walks
|
|
174
|
+
*/
|
|
175
|
+
generateWalks(walksPerNode?: number | null, walkLength?: number | null): string
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Configuration for automatic embedding generation
|
|
180
|
+
*/
|
|
181
|
+
export interface EmbeddingConfig {
|
|
182
|
+
/** Vector dimensionality (default: 128) */
|
|
183
|
+
vectorSize?: number | null
|
|
184
|
+
/** Window size for Word2Vec (default: 5) */
|
|
185
|
+
windowSize?: number | null
|
|
186
|
+
/** Number of walks per entity (default: 10) */
|
|
187
|
+
walksPerNode?: number | null
|
|
188
|
+
/** Maximum walk length (default: 5) */
|
|
189
|
+
walkLength?: number | null
|
|
74
190
|
}
|
|
75
191
|
|
|
76
192
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rust-kgdb",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.13",
|
|
4
4
|
"description": "High-performance RDF/SPARQL database with AI agent framework and cross-database federation. GraphDB (449ns lookups, 5-11x faster than RDFox), HyperFederate (KGDB + Snowflake + BigQuery), GraphFrames analytics, 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",
|
|
Binary file
|