@soulcraft/brainy 3.48.0 → 3.49.0
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/dist/api/UniversalImportAPI.d.ts +11 -1
- package/dist/api/UniversalImportAPI.js +93 -24
- package/dist/brainy.d.ts +5 -1
- package/dist/import/ImportCoordinator.d.ts +5 -1
- package/dist/import/ImportCoordinator.js +13 -1
- package/dist/importers/SmartImportOrchestrator.d.ts +1 -1
- package/dist/importers/SmartImportOrchestrator.js +65 -12
- package/package.json +1 -1
|
@@ -46,6 +46,14 @@ export interface NeuralImportResult {
|
|
|
46
46
|
processingTimeMs: number;
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
+
export interface NeuralImportProgress {
|
|
50
|
+
phase: 'extracting' | 'storing-entities' | 'storing-relationships' | 'complete';
|
|
51
|
+
message: string;
|
|
52
|
+
current: number;
|
|
53
|
+
total: number;
|
|
54
|
+
entities?: number;
|
|
55
|
+
relationships?: number;
|
|
56
|
+
}
|
|
49
57
|
export declare class UniversalImportAPI {
|
|
50
58
|
private brain;
|
|
51
59
|
private typeMatcher;
|
|
@@ -60,7 +68,9 @@ export declare class UniversalImportAPI {
|
|
|
60
68
|
* Universal import - handles ANY data source
|
|
61
69
|
* ALWAYS uses neural matching, NEVER falls back
|
|
62
70
|
*/
|
|
63
|
-
import(source: ImportSource | string | any
|
|
71
|
+
import(source: ImportSource | string | any, options?: {
|
|
72
|
+
onProgress?: (progress: NeuralImportProgress) => void;
|
|
73
|
+
}): Promise<NeuralImportResult>;
|
|
64
74
|
/**
|
|
65
75
|
* Import from URL - fetches and processes
|
|
66
76
|
*/
|
|
@@ -34,17 +34,31 @@ export class UniversalImportAPI {
|
|
|
34
34
|
* Universal import - handles ANY data source
|
|
35
35
|
* ALWAYS uses neural matching, NEVER falls back
|
|
36
36
|
*/
|
|
37
|
-
async import(source) {
|
|
37
|
+
async import(source, options) {
|
|
38
38
|
const startTime = Date.now();
|
|
39
39
|
// Normalize source
|
|
40
40
|
const normalizedSource = this.normalizeSource(source);
|
|
41
|
+
options?.onProgress?.({
|
|
42
|
+
phase: 'extracting',
|
|
43
|
+
message: 'Extracting data from source...',
|
|
44
|
+
current: 0,
|
|
45
|
+
total: 0
|
|
46
|
+
});
|
|
41
47
|
// Extract data based on source type
|
|
42
48
|
const extractedData = await this.extractData(normalizedSource);
|
|
43
49
|
// Neural processing - MANDATORY
|
|
44
50
|
const neuralResults = await this.neuralProcess(extractedData);
|
|
45
51
|
// Store in brain
|
|
46
|
-
const result = await this.storeInBrain(neuralResults);
|
|
52
|
+
const result = await this.storeInBrain(neuralResults, options?.onProgress);
|
|
47
53
|
result.stats.processingTimeMs = Date.now() - startTime;
|
|
54
|
+
options?.onProgress?.({
|
|
55
|
+
phase: 'complete',
|
|
56
|
+
message: 'Import complete',
|
|
57
|
+
current: result.stats.entitiesCreated + result.stats.relationshipsCreated,
|
|
58
|
+
total: result.stats.totalProcessed,
|
|
59
|
+
entities: result.stats.entitiesCreated,
|
|
60
|
+
relationships: result.stats.relationshipsCreated
|
|
61
|
+
});
|
|
48
62
|
return result;
|
|
49
63
|
}
|
|
50
64
|
/**
|
|
@@ -399,7 +413,7 @@ export class UniversalImportAPI {
|
|
|
399
413
|
/**
|
|
400
414
|
* Store processed data in brain
|
|
401
415
|
*/
|
|
402
|
-
async storeInBrain(neuralResults) {
|
|
416
|
+
async storeInBrain(neuralResults, onProgress) {
|
|
403
417
|
const result = {
|
|
404
418
|
entities: [],
|
|
405
419
|
relationships: [],
|
|
@@ -413,6 +427,13 @@ export class UniversalImportAPI {
|
|
|
413
427
|
};
|
|
414
428
|
let totalConfidence = 0;
|
|
415
429
|
// Store entities
|
|
430
|
+
onProgress?.({
|
|
431
|
+
phase: 'storing-entities',
|
|
432
|
+
message: 'Storing entities...',
|
|
433
|
+
current: 0,
|
|
434
|
+
total: neuralResults.entities.size
|
|
435
|
+
});
|
|
436
|
+
let entitiesProcessed = 0;
|
|
416
437
|
for (const entity of neuralResults.entities.values()) {
|
|
417
438
|
const id = await this.brain.add({
|
|
418
439
|
data: entity.data,
|
|
@@ -428,30 +449,78 @@ export class UniversalImportAPI {
|
|
|
428
449
|
});
|
|
429
450
|
result.stats.entitiesCreated++;
|
|
430
451
|
totalConfidence += entity.confidence;
|
|
452
|
+
entitiesProcessed++;
|
|
453
|
+
// Report progress periodically
|
|
454
|
+
if (entitiesProcessed % 10 === 0 || entitiesProcessed === neuralResults.entities.size) {
|
|
455
|
+
onProgress?.({
|
|
456
|
+
phase: 'storing-entities',
|
|
457
|
+
message: `Storing entities: ${entitiesProcessed}/${neuralResults.entities.size}`,
|
|
458
|
+
current: entitiesProcessed,
|
|
459
|
+
total: neuralResults.entities.size,
|
|
460
|
+
entities: entitiesProcessed
|
|
461
|
+
});
|
|
462
|
+
}
|
|
431
463
|
}
|
|
432
|
-
// Store relationships
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
464
|
+
// Store relationships using batch processing
|
|
465
|
+
if (neuralResults.relationships.size > 0) {
|
|
466
|
+
onProgress?.({
|
|
467
|
+
phase: 'storing-relationships',
|
|
468
|
+
message: 'Preparing relationships...',
|
|
469
|
+
current: 0,
|
|
470
|
+
total: neuralResults.relationships.size
|
|
471
|
+
});
|
|
472
|
+
// Collect all relationship parameters
|
|
473
|
+
const relationshipParams = [];
|
|
474
|
+
for (const relation of neuralResults.relationships.values()) {
|
|
475
|
+
// Map to actual entity IDs
|
|
476
|
+
const sourceEntity = Array.from(neuralResults.entities.values())
|
|
477
|
+
.find(e => e.id === relation.from);
|
|
478
|
+
const targetEntity = Array.from(neuralResults.entities.values())
|
|
479
|
+
.find(e => e.id === relation.to);
|
|
480
|
+
if (sourceEntity && targetEntity) {
|
|
481
|
+
relationshipParams.push({
|
|
482
|
+
from: sourceEntity.id,
|
|
483
|
+
to: targetEntity.id,
|
|
484
|
+
type: relation.type,
|
|
485
|
+
weight: relation.weight,
|
|
486
|
+
metadata: relation.metadata
|
|
487
|
+
});
|
|
488
|
+
totalConfidence += relation.confidence;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
// Batch create relationships with progress
|
|
492
|
+
if (relationshipParams.length > 0) {
|
|
493
|
+
const relationshipIds = await this.brain.relateMany({
|
|
494
|
+
items: relationshipParams,
|
|
495
|
+
parallel: true,
|
|
496
|
+
chunkSize: 100,
|
|
497
|
+
continueOnError: true,
|
|
498
|
+
onProgress: (done, total) => {
|
|
499
|
+
onProgress?.({
|
|
500
|
+
phase: 'storing-relationships',
|
|
501
|
+
message: `Building relationships: ${done}/${total}`,
|
|
502
|
+
current: done,
|
|
503
|
+
total: total,
|
|
504
|
+
entities: result.stats.entitiesCreated,
|
|
505
|
+
relationships: done
|
|
506
|
+
});
|
|
507
|
+
}
|
|
446
508
|
});
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
id
|
|
450
|
-
|
|
451
|
-
|
|
509
|
+
// Map results back
|
|
510
|
+
relationshipIds.forEach((id, index) => {
|
|
511
|
+
if (id && relationshipParams[index]) {
|
|
512
|
+
result.relationships.push({
|
|
513
|
+
id,
|
|
514
|
+
from: relationshipParams[index].from,
|
|
515
|
+
to: relationshipParams[index].to,
|
|
516
|
+
type: relationshipParams[index].type,
|
|
517
|
+
weight: relationshipParams[index].weight || 1,
|
|
518
|
+
confidence: 0.5, // Default confidence
|
|
519
|
+
metadata: relationshipParams[index].metadata
|
|
520
|
+
});
|
|
521
|
+
}
|
|
452
522
|
});
|
|
453
|
-
result.stats.relationshipsCreated
|
|
454
|
-
totalConfidence += relation.confidence;
|
|
523
|
+
result.stats.relationshipsCreated = relationshipIds.length;
|
|
455
524
|
}
|
|
456
525
|
}
|
|
457
526
|
// Calculate average confidence
|
package/dist/brainy.d.ts
CHANGED
|
@@ -698,12 +698,16 @@ export declare class Brainy<T = any> implements BrainyInterface<T> {
|
|
|
698
698
|
enableConceptExtraction?: boolean;
|
|
699
699
|
confidenceThreshold?: number;
|
|
700
700
|
onProgress?: (progress: {
|
|
701
|
-
stage: 'detecting' | 'extracting' | 'storing-vfs' | 'storing-graph' | 'complete';
|
|
701
|
+
stage: 'detecting' | 'extracting' | 'storing-vfs' | 'storing-graph' | 'relationships' | 'complete';
|
|
702
|
+
phase?: 'extraction' | 'relationships';
|
|
702
703
|
message: string;
|
|
703
704
|
processed?: number;
|
|
705
|
+
current?: number;
|
|
704
706
|
total?: number;
|
|
705
707
|
entities?: number;
|
|
706
708
|
relationships?: number;
|
|
709
|
+
throughput?: number;
|
|
710
|
+
eta?: number;
|
|
707
711
|
}) => void;
|
|
708
712
|
}): Promise<import("./import/ImportCoordinator.js").ImportResult>;
|
|
709
713
|
/**
|
|
@@ -56,9 +56,13 @@ export interface ImportOptions {
|
|
|
56
56
|
onProgress?: (progress: ImportProgress) => void;
|
|
57
57
|
}
|
|
58
58
|
export interface ImportProgress {
|
|
59
|
-
stage: 'detecting' | 'extracting' | 'storing-vfs' | 'storing-graph' | 'complete';
|
|
59
|
+
stage: 'detecting' | 'extracting' | 'storing-vfs' | 'storing-graph' | 'relationships' | 'complete';
|
|
60
|
+
/** Phase of import - extraction or relationship building (v3.49.0) */
|
|
61
|
+
phase?: 'extraction' | 'relationships';
|
|
60
62
|
message: string;
|
|
61
63
|
processed?: number;
|
|
64
|
+
/** Alias for processed, used in relationship phase (v3.49.0) */
|
|
65
|
+
current?: number;
|
|
62
66
|
total?: number;
|
|
63
67
|
entities?: number;
|
|
64
68
|
relationships?: number;
|
|
@@ -460,7 +460,19 @@ export class ImportCoordinator {
|
|
|
460
460
|
items: relationshipParams,
|
|
461
461
|
parallel: true,
|
|
462
462
|
chunkSize: 100,
|
|
463
|
-
continueOnError: true
|
|
463
|
+
continueOnError: true,
|
|
464
|
+
onProgress: (done, total) => {
|
|
465
|
+
options.onProgress?.({
|
|
466
|
+
stage: 'storing-graph',
|
|
467
|
+
phase: 'relationships',
|
|
468
|
+
message: `Building relationships: ${done}/${total}`,
|
|
469
|
+
current: done,
|
|
470
|
+
processed: done,
|
|
471
|
+
total: total,
|
|
472
|
+
entities: entities.length,
|
|
473
|
+
relationships: done
|
|
474
|
+
});
|
|
475
|
+
}
|
|
464
476
|
});
|
|
465
477
|
// Update relationship IDs
|
|
466
478
|
relationshipIds.forEach((id, index) => {
|
|
@@ -29,7 +29,7 @@ export interface SmartImportOptions extends SmartExcelOptions {
|
|
|
29
29
|
filename?: string;
|
|
30
30
|
}
|
|
31
31
|
export interface SmartImportProgress {
|
|
32
|
-
phase: 'parsing' | 'extracting' | 'creating' | 'organizing' | 'complete';
|
|
32
|
+
phase: 'parsing' | 'extracting' | 'creating' | 'relationships' | 'organizing' | 'complete';
|
|
33
33
|
message: string;
|
|
34
34
|
processed: number;
|
|
35
35
|
total: number;
|
|
@@ -129,7 +129,7 @@ export class SmartImportOrchestrator {
|
|
|
129
129
|
if (options.createRelationships !== false && options.createEntities !== false) {
|
|
130
130
|
onProgress?.({
|
|
131
131
|
phase: 'creating',
|
|
132
|
-
message: '
|
|
132
|
+
message: 'Preparing relationships...',
|
|
133
133
|
processed: 0,
|
|
134
134
|
total: result.extraction.rows.length,
|
|
135
135
|
entities: result.entityIds.length,
|
|
@@ -140,7 +140,8 @@ export class SmartImportOrchestrator {
|
|
|
140
140
|
for (const extracted of result.extraction.rows) {
|
|
141
141
|
entityMap.set(extracted.entity.name.toLowerCase(), extracted.entity.id);
|
|
142
142
|
}
|
|
143
|
-
//
|
|
143
|
+
// Collect all relationship parameters
|
|
144
|
+
const relationshipParams = [];
|
|
144
145
|
for (const extracted of result.extraction.rows) {
|
|
145
146
|
for (const rel of extracted.relationships) {
|
|
146
147
|
try {
|
|
@@ -167,8 +168,8 @@ export class SmartImportOrchestrator {
|
|
|
167
168
|
});
|
|
168
169
|
result.entityIds.push(toEntityId);
|
|
169
170
|
}
|
|
170
|
-
//
|
|
171
|
-
|
|
171
|
+
// Collect relationship parameter
|
|
172
|
+
relationshipParams.push({
|
|
172
173
|
from: extracted.entity.id,
|
|
173
174
|
to: toEntityId,
|
|
174
175
|
type: rel.type,
|
|
@@ -177,14 +178,46 @@ export class SmartImportOrchestrator {
|
|
|
177
178
|
evidence: rel.evidence
|
|
178
179
|
}
|
|
179
180
|
});
|
|
180
|
-
result.relationshipIds.push(relId);
|
|
181
|
-
result.stats.relationshipsCreated++;
|
|
182
181
|
}
|
|
183
182
|
catch (error) {
|
|
184
|
-
result.errors.push(`Failed to
|
|
183
|
+
result.errors.push(`Failed to prepare relationship: ${error.message}`);
|
|
185
184
|
}
|
|
186
185
|
}
|
|
187
186
|
}
|
|
187
|
+
// Batch create all relationships with progress
|
|
188
|
+
if (relationshipParams.length > 0) {
|
|
189
|
+
onProgress?.({
|
|
190
|
+
phase: 'relationships',
|
|
191
|
+
message: 'Building relationships...',
|
|
192
|
+
processed: 0,
|
|
193
|
+
total: relationshipParams.length,
|
|
194
|
+
entities: result.entityIds.length,
|
|
195
|
+
relationships: 0
|
|
196
|
+
});
|
|
197
|
+
try {
|
|
198
|
+
const relationshipIds = await this.brain.relateMany({
|
|
199
|
+
items: relationshipParams,
|
|
200
|
+
parallel: true,
|
|
201
|
+
chunkSize: 100,
|
|
202
|
+
continueOnError: true,
|
|
203
|
+
onProgress: (done, total) => {
|
|
204
|
+
onProgress?.({
|
|
205
|
+
phase: 'relationships',
|
|
206
|
+
message: `Building relationships: ${done}/${total}`,
|
|
207
|
+
processed: done,
|
|
208
|
+
total: total,
|
|
209
|
+
entities: result.entityIds.length,
|
|
210
|
+
relationships: done
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
result.relationshipIds = relationshipIds;
|
|
215
|
+
result.stats.relationshipsCreated = relationshipIds.length;
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
result.errors.push(`Failed to create relationships: ${error.message}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
188
221
|
}
|
|
189
222
|
// Phase 4: Create VFS structure
|
|
190
223
|
if (options.createVFSStructure !== false) {
|
|
@@ -415,7 +448,9 @@ export class SmartImportOrchestrator {
|
|
|
415
448
|
}
|
|
416
449
|
}
|
|
417
450
|
if (options.createRelationships !== false && options.createEntities !== false) {
|
|
418
|
-
onProgress?.({ phase: 'creating', message: '
|
|
451
|
+
onProgress?.({ phase: 'creating', message: 'Preparing relationships...', processed: 0, total: result.extraction.rows.length, entities: result.entityIds.length, relationships: 0 });
|
|
452
|
+
// Collect all relationship parameters
|
|
453
|
+
const relationshipParams = [];
|
|
419
454
|
for (const extracted of result.extraction.rows) {
|
|
420
455
|
for (const rel of extracted.relationships) {
|
|
421
456
|
try {
|
|
@@ -430,15 +465,33 @@ export class SmartImportOrchestrator {
|
|
|
430
465
|
toEntityId = await this.brain.add({ data: rel.to, type: NounType.Thing, metadata: { name: rel.to, placeholder: true, extractedFrom: extracted.entity.name } });
|
|
431
466
|
result.entityIds.push(toEntityId);
|
|
432
467
|
}
|
|
433
|
-
|
|
434
|
-
result.relationshipIds.push(relId);
|
|
435
|
-
result.stats.relationshipsCreated++;
|
|
468
|
+
relationshipParams.push({ from: extracted.entity.id, to: toEntityId, type: rel.type, metadata: { confidence: rel.confidence, evidence: rel.evidence } });
|
|
436
469
|
}
|
|
437
470
|
catch (error) {
|
|
438
|
-
result.errors.push(`Failed to
|
|
471
|
+
result.errors.push(`Failed to prepare relationship: ${error.message}`);
|
|
439
472
|
}
|
|
440
473
|
}
|
|
441
474
|
}
|
|
475
|
+
// Batch create all relationships with progress
|
|
476
|
+
if (relationshipParams.length > 0) {
|
|
477
|
+
onProgress?.({ phase: 'relationships', message: 'Building relationships...', processed: 0, total: relationshipParams.length, entities: result.entityIds.length, relationships: 0 });
|
|
478
|
+
try {
|
|
479
|
+
const relationshipIds = await this.brain.relateMany({
|
|
480
|
+
items: relationshipParams,
|
|
481
|
+
parallel: true,
|
|
482
|
+
chunkSize: 100,
|
|
483
|
+
continueOnError: true,
|
|
484
|
+
onProgress: (done, total) => {
|
|
485
|
+
onProgress?.({ phase: 'relationships', message: `Building relationships: ${done}/${total}`, processed: done, total: total, entities: result.entityIds.length, relationships: done });
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
result.relationshipIds = relationshipIds;
|
|
489
|
+
result.stats.relationshipsCreated = relationshipIds.length;
|
|
490
|
+
}
|
|
491
|
+
catch (error) {
|
|
492
|
+
result.errors.push(`Failed to create relationships: ${error.message}`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
442
495
|
}
|
|
443
496
|
}
|
|
444
497
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soulcraft/brainy",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.49.0",
|
|
4
4
|
"description": "Universal Knowledge Protocol™ - World's first Triple Intelligence database unifying vector, graph, and document search in one API. 31 nouns × 40 verbs for infinite expressiveness.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|