@soulcraft/brainy 3.44.0 → 3.46.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/CHANGELOG.md +89 -0
- package/dist/augmentations/KnowledgeAugmentation.d.ts +40 -0
- package/dist/augmentations/KnowledgeAugmentation.js +251 -0
- package/dist/brainy.d.ts +8 -1
- package/dist/brainy.js +25 -1
- package/dist/neural/embeddedTypeEmbeddings.d.ts +1 -1
- package/dist/neural/embeddedTypeEmbeddings.js +2 -2
- package/dist/storage/adapters/typeAwareStorageAdapter.d.ts +210 -0
- package/dist/storage/adapters/typeAwareStorageAdapter.js +626 -0
- package/dist/storage/storageFactory.d.ts +23 -2
- package/dist/storage/storageFactory.js +19 -1
- package/dist/types/brainyDataInterface.d.ts +52 -0
- package/dist/types/brainyDataInterface.js +10 -0
- package/dist/types/graphTypes.d.ts +132 -0
- package/dist/types/graphTypes.js +172 -0
- package/dist/utils/metadataIndex.d.ts +73 -2
- package/dist/utils/metadataIndex.js +316 -74
- package/dist/vfs/ConceptSystem.d.ts +203 -0
- package/dist/vfs/ConceptSystem.js +545 -0
- package/dist/vfs/EntityManager.d.ts +75 -0
- package/dist/vfs/EntityManager.js +216 -0
- package/dist/vfs/EventRecorder.d.ts +84 -0
- package/dist/vfs/EventRecorder.js +269 -0
- package/dist/vfs/GitBridge.d.ts +167 -0
- package/dist/vfs/GitBridge.js +537 -0
- package/dist/vfs/KnowledgeLayer.d.ts +35 -0
- package/dist/vfs/KnowledgeLayer.js +443 -0
- package/dist/vfs/PersistentEntitySystem.d.ts +165 -0
- package/dist/vfs/PersistentEntitySystem.js +503 -0
- package/dist/vfs/SemanticVersioning.d.ts +105 -0
- package/dist/vfs/SemanticVersioning.js +309 -0
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ import { MemoryStorage } from './adapters/memoryStorage.js';
|
|
|
6
6
|
import { OPFSStorage } from './adapters/opfsStorage.js';
|
|
7
7
|
import { S3CompatibleStorage, R2Storage } from './adapters/s3CompatibleStorage.js';
|
|
8
8
|
import { GcsStorage } from './adapters/gcsStorage.js';
|
|
9
|
+
import { TypeAwareStorageAdapter } from './adapters/typeAwareStorageAdapter.js';
|
|
9
10
|
// FileSystemStorage is dynamically imported to avoid issues in browser environments
|
|
10
11
|
import { isBrowser } from '../utils/environment.js';
|
|
11
12
|
/**
|
|
@@ -156,6 +157,23 @@ export async function createStorage(options = {}) {
|
|
|
156
157
|
console.warn('GCS native storage configuration is missing, falling back to memory storage');
|
|
157
158
|
return new MemoryStorage();
|
|
158
159
|
}
|
|
160
|
+
case 'type-aware': {
|
|
161
|
+
console.log('Using Type-Aware Storage (type-first architecture)');
|
|
162
|
+
// Create underlying storage adapter
|
|
163
|
+
const underlyingType = options.typeAwareStorage?.underlyingType || 'auto';
|
|
164
|
+
const underlyingOptions = options.typeAwareStorage?.underlyingOptions || {};
|
|
165
|
+
// Recursively create the underlying storage
|
|
166
|
+
const underlying = await createStorage({
|
|
167
|
+
...underlyingOptions,
|
|
168
|
+
type: underlyingType
|
|
169
|
+
});
|
|
170
|
+
// Wrap with TypeAwareStorageAdapter
|
|
171
|
+
// Cast to BaseStorage since all concrete storage adapters extend BaseStorage
|
|
172
|
+
return new TypeAwareStorageAdapter({
|
|
173
|
+
underlyingStorage: underlying,
|
|
174
|
+
verbose: options.typeAwareStorage?.verbose || false
|
|
175
|
+
});
|
|
176
|
+
}
|
|
159
177
|
default:
|
|
160
178
|
console.warn(`Unknown storage type: ${options.type}, falling back to memory storage`);
|
|
161
179
|
return new MemoryStorage();
|
|
@@ -269,7 +287,7 @@ export async function createStorage(options = {}) {
|
|
|
269
287
|
/**
|
|
270
288
|
* Export storage adapters
|
|
271
289
|
*/
|
|
272
|
-
export { MemoryStorage, OPFSStorage, S3CompatibleStorage, R2Storage, GcsStorage };
|
|
290
|
+
export { MemoryStorage, OPFSStorage, S3CompatibleStorage, R2Storage, GcsStorage, TypeAwareStorageAdapter };
|
|
273
291
|
// Export FileSystemStorage conditionally
|
|
274
292
|
// NOTE: FileSystemStorage is now only imported dynamically to avoid fs imports in browser builds
|
|
275
293
|
// export { FileSystemStorage } from './adapters/fileSystemStorage.js'
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BrainyInterface - Modern API Only
|
|
3
|
+
*
|
|
4
|
+
* This interface defines the MODERN methods from Brainy 3.0.
|
|
5
|
+
* Used to break circular dependencies while enforcing modern API usage.
|
|
6
|
+
*
|
|
7
|
+
* NO DEPRECATED METHODS - Only clean, modern API patterns.
|
|
8
|
+
*/
|
|
9
|
+
import { Vector } from '../coreTypes.js';
|
|
10
|
+
import { AddParams, RelateParams, Result, Entity, FindParams, SimilarParams } from './brainy.types.js';
|
|
11
|
+
export interface BrainyInterface<T = unknown> {
|
|
12
|
+
/**
|
|
13
|
+
* Initialize the database
|
|
14
|
+
*/
|
|
15
|
+
init(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Modern add method - unified entity creation
|
|
18
|
+
* @param params Parameters for adding entities
|
|
19
|
+
* @returns The ID of the created entity
|
|
20
|
+
*/
|
|
21
|
+
add(params: AddParams<T>): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Modern relate method - unified relationship creation
|
|
24
|
+
* @param params Parameters for creating relationships
|
|
25
|
+
* @returns The ID of the created relationship
|
|
26
|
+
*/
|
|
27
|
+
relate(params: RelateParams<T>): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Modern find method - unified search and discovery
|
|
30
|
+
* @param query Search query or parameters object
|
|
31
|
+
* @returns Array of search results
|
|
32
|
+
*/
|
|
33
|
+
find(query: string | FindParams<T>): Promise<Result<T>[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Modern get method - retrieve entities by ID
|
|
36
|
+
* @param id The entity ID to retrieve
|
|
37
|
+
* @returns Entity or null if not found
|
|
38
|
+
*/
|
|
39
|
+
get(id: string): Promise<Entity<T> | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Modern similar method - find similar entities
|
|
42
|
+
* @param params Parameters for similarity search
|
|
43
|
+
* @returns Array of similar entities with scores
|
|
44
|
+
*/
|
|
45
|
+
similar(params: SimilarParams<T>): Promise<Result<T>[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Generate embedding vector from text
|
|
48
|
+
* @param text The text to embed
|
|
49
|
+
* @returns Vector representation of the text
|
|
50
|
+
*/
|
|
51
|
+
embed(text: string): Promise<Vector>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BrainyInterface - Modern API Only
|
|
3
|
+
*
|
|
4
|
+
* This interface defines the MODERN methods from Brainy 3.0.
|
|
5
|
+
* Used to break circular dependencies while enforcing modern API usage.
|
|
6
|
+
*
|
|
7
|
+
* NO DEPRECATED METHODS - Only clean, modern API patterns.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=brainyDataInterface.js.map
|
|
@@ -428,4 +428,136 @@ export declare const VerbType: {
|
|
|
428
428
|
readonly Competes: "competes";
|
|
429
429
|
};
|
|
430
430
|
export type VerbType = (typeof VerbType)[keyof typeof VerbType];
|
|
431
|
+
/**
|
|
432
|
+
* Noun type enum for O(1) lookups and type safety
|
|
433
|
+
* Maps each noun type to a unique index (0-30)
|
|
434
|
+
* Used for fixed-size array operations and bitmap indices
|
|
435
|
+
*/
|
|
436
|
+
export declare enum NounTypeEnum {
|
|
437
|
+
person = 0,
|
|
438
|
+
organization = 1,
|
|
439
|
+
location = 2,
|
|
440
|
+
thing = 3,
|
|
441
|
+
concept = 4,
|
|
442
|
+
event = 5,
|
|
443
|
+
document = 6,
|
|
444
|
+
media = 7,
|
|
445
|
+
file = 8,
|
|
446
|
+
message = 9,
|
|
447
|
+
content = 10,
|
|
448
|
+
collection = 11,
|
|
449
|
+
dataset = 12,
|
|
450
|
+
product = 13,
|
|
451
|
+
service = 14,
|
|
452
|
+
user = 15,
|
|
453
|
+
task = 16,
|
|
454
|
+
project = 17,
|
|
455
|
+
process = 18,
|
|
456
|
+
state = 19,
|
|
457
|
+
role = 20,
|
|
458
|
+
topic = 21,
|
|
459
|
+
language = 22,
|
|
460
|
+
currency = 23,
|
|
461
|
+
measurement = 24,
|
|
462
|
+
hypothesis = 25,
|
|
463
|
+
experiment = 26,
|
|
464
|
+
contract = 27,
|
|
465
|
+
regulation = 28,
|
|
466
|
+
interface = 29,
|
|
467
|
+
resource = 30
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Verb type enum for O(1) lookups and type safety
|
|
471
|
+
* Maps each verb type to a unique index (0-39)
|
|
472
|
+
* Used for fixed-size array operations and bitmap indices
|
|
473
|
+
*/
|
|
474
|
+
export declare enum VerbTypeEnum {
|
|
475
|
+
relatedTo = 0,
|
|
476
|
+
contains = 1,
|
|
477
|
+
partOf = 2,
|
|
478
|
+
locatedAt = 3,
|
|
479
|
+
references = 4,
|
|
480
|
+
precedes = 5,
|
|
481
|
+
succeeds = 6,
|
|
482
|
+
causes = 7,
|
|
483
|
+
dependsOn = 8,
|
|
484
|
+
requires = 9,
|
|
485
|
+
creates = 10,
|
|
486
|
+
transforms = 11,
|
|
487
|
+
becomes = 12,
|
|
488
|
+
modifies = 13,
|
|
489
|
+
consumes = 14,
|
|
490
|
+
owns = 15,
|
|
491
|
+
attributedTo = 16,
|
|
492
|
+
createdBy = 17,
|
|
493
|
+
belongsTo = 18,
|
|
494
|
+
memberOf = 19,
|
|
495
|
+
worksWith = 20,
|
|
496
|
+
friendOf = 21,
|
|
497
|
+
follows = 22,
|
|
498
|
+
likes = 23,
|
|
499
|
+
reportsTo = 24,
|
|
500
|
+
supervises = 25,
|
|
501
|
+
mentors = 26,
|
|
502
|
+
communicates = 27,
|
|
503
|
+
describes = 28,
|
|
504
|
+
defines = 29,
|
|
505
|
+
categorizes = 30,
|
|
506
|
+
measures = 31,
|
|
507
|
+
evaluates = 32,
|
|
508
|
+
uses = 33,
|
|
509
|
+
implements = 34,
|
|
510
|
+
extends = 35,
|
|
511
|
+
inherits = 36,
|
|
512
|
+
conflicts = 37,
|
|
513
|
+
synchronizes = 38,
|
|
514
|
+
competes = 39
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Total number of noun types (for array allocations)
|
|
518
|
+
*/
|
|
519
|
+
export declare const NOUN_TYPE_COUNT = 31;
|
|
520
|
+
/**
|
|
521
|
+
* Total number of verb types (for array allocations)
|
|
522
|
+
*/
|
|
523
|
+
export declare const VERB_TYPE_COUNT = 40;
|
|
524
|
+
/**
|
|
525
|
+
* Type utilities for O(1) conversions between string types and numeric indices
|
|
526
|
+
* Enables efficient fixed-size array operations and bitmap indexing
|
|
527
|
+
*/
|
|
528
|
+
export declare const TypeUtils: {
|
|
529
|
+
/**
|
|
530
|
+
* Get numeric index for a noun type
|
|
531
|
+
* @param type - NounType string (e.g., 'person')
|
|
532
|
+
* @returns Numeric index (0-30)
|
|
533
|
+
*/
|
|
534
|
+
getNounIndex: (type: NounType) => number;
|
|
535
|
+
/**
|
|
536
|
+
* Get numeric index for a verb type
|
|
537
|
+
* @param type - VerbType string (e.g., 'relatedTo')
|
|
538
|
+
* @returns Numeric index (0-39)
|
|
539
|
+
*/
|
|
540
|
+
getVerbIndex: (type: VerbType) => number;
|
|
541
|
+
/**
|
|
542
|
+
* Get noun type string from numeric index
|
|
543
|
+
* @param index - Numeric index (0-30)
|
|
544
|
+
* @returns NounType string or 'thing' as default
|
|
545
|
+
*/
|
|
546
|
+
getNounFromIndex: (index: number) => NounType;
|
|
547
|
+
/**
|
|
548
|
+
* Get verb type string from numeric index
|
|
549
|
+
* @param index - Numeric index (0-39)
|
|
550
|
+
* @returns VerbType string or 'relatedTo' as default
|
|
551
|
+
*/
|
|
552
|
+
getVerbFromIndex: (index: number) => VerbType;
|
|
553
|
+
};
|
|
554
|
+
/**
|
|
555
|
+
* Type-specific metadata for optimization hints
|
|
556
|
+
* Provides per-type configuration for bloom filters, chunking, and indexing
|
|
557
|
+
*/
|
|
558
|
+
export declare const TypeMetadata: Record<NounType, {
|
|
559
|
+
expectedFields: number;
|
|
560
|
+
bloomBits: number;
|
|
561
|
+
avgChunkSize: number;
|
|
562
|
+
}>;
|
|
431
563
|
export {};
|
package/dist/types/graphTypes.js
CHANGED
|
@@ -258,4 +258,176 @@ export const VerbType = {
|
|
|
258
258
|
Synchronizes: 'synchronizes', // Coordination, timing, synchronized operations
|
|
259
259
|
Competes: 'competes' // Competition, rivalry, competing relationships
|
|
260
260
|
};
|
|
261
|
+
/**
|
|
262
|
+
* Noun type enum for O(1) lookups and type safety
|
|
263
|
+
* Maps each noun type to a unique index (0-30)
|
|
264
|
+
* Used for fixed-size array operations and bitmap indices
|
|
265
|
+
*/
|
|
266
|
+
export var NounTypeEnum;
|
|
267
|
+
(function (NounTypeEnum) {
|
|
268
|
+
NounTypeEnum[NounTypeEnum["person"] = 0] = "person";
|
|
269
|
+
NounTypeEnum[NounTypeEnum["organization"] = 1] = "organization";
|
|
270
|
+
NounTypeEnum[NounTypeEnum["location"] = 2] = "location";
|
|
271
|
+
NounTypeEnum[NounTypeEnum["thing"] = 3] = "thing";
|
|
272
|
+
NounTypeEnum[NounTypeEnum["concept"] = 4] = "concept";
|
|
273
|
+
NounTypeEnum[NounTypeEnum["event"] = 5] = "event";
|
|
274
|
+
NounTypeEnum[NounTypeEnum["document"] = 6] = "document";
|
|
275
|
+
NounTypeEnum[NounTypeEnum["media"] = 7] = "media";
|
|
276
|
+
NounTypeEnum[NounTypeEnum["file"] = 8] = "file";
|
|
277
|
+
NounTypeEnum[NounTypeEnum["message"] = 9] = "message";
|
|
278
|
+
NounTypeEnum[NounTypeEnum["content"] = 10] = "content";
|
|
279
|
+
NounTypeEnum[NounTypeEnum["collection"] = 11] = "collection";
|
|
280
|
+
NounTypeEnum[NounTypeEnum["dataset"] = 12] = "dataset";
|
|
281
|
+
NounTypeEnum[NounTypeEnum["product"] = 13] = "product";
|
|
282
|
+
NounTypeEnum[NounTypeEnum["service"] = 14] = "service";
|
|
283
|
+
NounTypeEnum[NounTypeEnum["user"] = 15] = "user";
|
|
284
|
+
NounTypeEnum[NounTypeEnum["task"] = 16] = "task";
|
|
285
|
+
NounTypeEnum[NounTypeEnum["project"] = 17] = "project";
|
|
286
|
+
NounTypeEnum[NounTypeEnum["process"] = 18] = "process";
|
|
287
|
+
NounTypeEnum[NounTypeEnum["state"] = 19] = "state";
|
|
288
|
+
NounTypeEnum[NounTypeEnum["role"] = 20] = "role";
|
|
289
|
+
NounTypeEnum[NounTypeEnum["topic"] = 21] = "topic";
|
|
290
|
+
NounTypeEnum[NounTypeEnum["language"] = 22] = "language";
|
|
291
|
+
NounTypeEnum[NounTypeEnum["currency"] = 23] = "currency";
|
|
292
|
+
NounTypeEnum[NounTypeEnum["measurement"] = 24] = "measurement";
|
|
293
|
+
NounTypeEnum[NounTypeEnum["hypothesis"] = 25] = "hypothesis";
|
|
294
|
+
NounTypeEnum[NounTypeEnum["experiment"] = 26] = "experiment";
|
|
295
|
+
NounTypeEnum[NounTypeEnum["contract"] = 27] = "contract";
|
|
296
|
+
NounTypeEnum[NounTypeEnum["regulation"] = 28] = "regulation";
|
|
297
|
+
NounTypeEnum[NounTypeEnum["interface"] = 29] = "interface";
|
|
298
|
+
NounTypeEnum[NounTypeEnum["resource"] = 30] = "resource";
|
|
299
|
+
})(NounTypeEnum || (NounTypeEnum = {}));
|
|
300
|
+
/**
|
|
301
|
+
* Verb type enum for O(1) lookups and type safety
|
|
302
|
+
* Maps each verb type to a unique index (0-39)
|
|
303
|
+
* Used for fixed-size array operations and bitmap indices
|
|
304
|
+
*/
|
|
305
|
+
export var VerbTypeEnum;
|
|
306
|
+
(function (VerbTypeEnum) {
|
|
307
|
+
VerbTypeEnum[VerbTypeEnum["relatedTo"] = 0] = "relatedTo";
|
|
308
|
+
VerbTypeEnum[VerbTypeEnum["contains"] = 1] = "contains";
|
|
309
|
+
VerbTypeEnum[VerbTypeEnum["partOf"] = 2] = "partOf";
|
|
310
|
+
VerbTypeEnum[VerbTypeEnum["locatedAt"] = 3] = "locatedAt";
|
|
311
|
+
VerbTypeEnum[VerbTypeEnum["references"] = 4] = "references";
|
|
312
|
+
VerbTypeEnum[VerbTypeEnum["precedes"] = 5] = "precedes";
|
|
313
|
+
VerbTypeEnum[VerbTypeEnum["succeeds"] = 6] = "succeeds";
|
|
314
|
+
VerbTypeEnum[VerbTypeEnum["causes"] = 7] = "causes";
|
|
315
|
+
VerbTypeEnum[VerbTypeEnum["dependsOn"] = 8] = "dependsOn";
|
|
316
|
+
VerbTypeEnum[VerbTypeEnum["requires"] = 9] = "requires";
|
|
317
|
+
VerbTypeEnum[VerbTypeEnum["creates"] = 10] = "creates";
|
|
318
|
+
VerbTypeEnum[VerbTypeEnum["transforms"] = 11] = "transforms";
|
|
319
|
+
VerbTypeEnum[VerbTypeEnum["becomes"] = 12] = "becomes";
|
|
320
|
+
VerbTypeEnum[VerbTypeEnum["modifies"] = 13] = "modifies";
|
|
321
|
+
VerbTypeEnum[VerbTypeEnum["consumes"] = 14] = "consumes";
|
|
322
|
+
VerbTypeEnum[VerbTypeEnum["owns"] = 15] = "owns";
|
|
323
|
+
VerbTypeEnum[VerbTypeEnum["attributedTo"] = 16] = "attributedTo";
|
|
324
|
+
VerbTypeEnum[VerbTypeEnum["createdBy"] = 17] = "createdBy";
|
|
325
|
+
VerbTypeEnum[VerbTypeEnum["belongsTo"] = 18] = "belongsTo";
|
|
326
|
+
VerbTypeEnum[VerbTypeEnum["memberOf"] = 19] = "memberOf";
|
|
327
|
+
VerbTypeEnum[VerbTypeEnum["worksWith"] = 20] = "worksWith";
|
|
328
|
+
VerbTypeEnum[VerbTypeEnum["friendOf"] = 21] = "friendOf";
|
|
329
|
+
VerbTypeEnum[VerbTypeEnum["follows"] = 22] = "follows";
|
|
330
|
+
VerbTypeEnum[VerbTypeEnum["likes"] = 23] = "likes";
|
|
331
|
+
VerbTypeEnum[VerbTypeEnum["reportsTo"] = 24] = "reportsTo";
|
|
332
|
+
VerbTypeEnum[VerbTypeEnum["supervises"] = 25] = "supervises";
|
|
333
|
+
VerbTypeEnum[VerbTypeEnum["mentors"] = 26] = "mentors";
|
|
334
|
+
VerbTypeEnum[VerbTypeEnum["communicates"] = 27] = "communicates";
|
|
335
|
+
VerbTypeEnum[VerbTypeEnum["describes"] = 28] = "describes";
|
|
336
|
+
VerbTypeEnum[VerbTypeEnum["defines"] = 29] = "defines";
|
|
337
|
+
VerbTypeEnum[VerbTypeEnum["categorizes"] = 30] = "categorizes";
|
|
338
|
+
VerbTypeEnum[VerbTypeEnum["measures"] = 31] = "measures";
|
|
339
|
+
VerbTypeEnum[VerbTypeEnum["evaluates"] = 32] = "evaluates";
|
|
340
|
+
VerbTypeEnum[VerbTypeEnum["uses"] = 33] = "uses";
|
|
341
|
+
VerbTypeEnum[VerbTypeEnum["implements"] = 34] = "implements";
|
|
342
|
+
VerbTypeEnum[VerbTypeEnum["extends"] = 35] = "extends";
|
|
343
|
+
VerbTypeEnum[VerbTypeEnum["inherits"] = 36] = "inherits";
|
|
344
|
+
VerbTypeEnum[VerbTypeEnum["conflicts"] = 37] = "conflicts";
|
|
345
|
+
VerbTypeEnum[VerbTypeEnum["synchronizes"] = 38] = "synchronizes";
|
|
346
|
+
VerbTypeEnum[VerbTypeEnum["competes"] = 39] = "competes";
|
|
347
|
+
})(VerbTypeEnum || (VerbTypeEnum = {}));
|
|
348
|
+
/**
|
|
349
|
+
* Total number of noun types (for array allocations)
|
|
350
|
+
*/
|
|
351
|
+
export const NOUN_TYPE_COUNT = 31;
|
|
352
|
+
/**
|
|
353
|
+
* Total number of verb types (for array allocations)
|
|
354
|
+
*/
|
|
355
|
+
export const VERB_TYPE_COUNT = 40;
|
|
356
|
+
/**
|
|
357
|
+
* Type utilities for O(1) conversions between string types and numeric indices
|
|
358
|
+
* Enables efficient fixed-size array operations and bitmap indexing
|
|
359
|
+
*/
|
|
360
|
+
export const TypeUtils = {
|
|
361
|
+
/**
|
|
362
|
+
* Get numeric index for a noun type
|
|
363
|
+
* @param type - NounType string (e.g., 'person')
|
|
364
|
+
* @returns Numeric index (0-30)
|
|
365
|
+
*/
|
|
366
|
+
getNounIndex: (type) => {
|
|
367
|
+
return NounTypeEnum[type];
|
|
368
|
+
},
|
|
369
|
+
/**
|
|
370
|
+
* Get numeric index for a verb type
|
|
371
|
+
* @param type - VerbType string (e.g., 'relatedTo')
|
|
372
|
+
* @returns Numeric index (0-39)
|
|
373
|
+
*/
|
|
374
|
+
getVerbIndex: (type) => {
|
|
375
|
+
return VerbTypeEnum[type];
|
|
376
|
+
},
|
|
377
|
+
/**
|
|
378
|
+
* Get noun type string from numeric index
|
|
379
|
+
* @param index - Numeric index (0-30)
|
|
380
|
+
* @returns NounType string or 'thing' as default
|
|
381
|
+
*/
|
|
382
|
+
getNounFromIndex: (index) => {
|
|
383
|
+
const entry = Object.entries(NounTypeEnum).find(([_, idx]) => idx === index);
|
|
384
|
+
return entry ? entry[0] : NounType.Thing;
|
|
385
|
+
},
|
|
386
|
+
/**
|
|
387
|
+
* Get verb type string from numeric index
|
|
388
|
+
* @param index - Numeric index (0-39)
|
|
389
|
+
* @returns VerbType string or 'relatedTo' as default
|
|
390
|
+
*/
|
|
391
|
+
getVerbFromIndex: (index) => {
|
|
392
|
+
const entry = Object.entries(VerbTypeEnum).find(([_, idx]) => idx === index);
|
|
393
|
+
return entry ? entry[0] : VerbType.RelatedTo;
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* Type-specific metadata for optimization hints
|
|
398
|
+
* Provides per-type configuration for bloom filters, chunking, and indexing
|
|
399
|
+
*/
|
|
400
|
+
export const TypeMetadata = {
|
|
401
|
+
person: { expectedFields: 10, bloomBits: 256, avgChunkSize: 100 },
|
|
402
|
+
organization: { expectedFields: 12, bloomBits: 256, avgChunkSize: 80 },
|
|
403
|
+
document: { expectedFields: 8, bloomBits: 256, avgChunkSize: 100 },
|
|
404
|
+
event: { expectedFields: 6, bloomBits: 128, avgChunkSize: 50 },
|
|
405
|
+
location: { expectedFields: 7, bloomBits: 128, avgChunkSize: 60 },
|
|
406
|
+
thing: { expectedFields: 5, bloomBits: 128, avgChunkSize: 50 },
|
|
407
|
+
concept: { expectedFields: 4, bloomBits: 128, avgChunkSize: 40 },
|
|
408
|
+
media: { expectedFields: 6, bloomBits: 128, avgChunkSize: 50 },
|
|
409
|
+
file: { expectedFields: 5, bloomBits: 128, avgChunkSize: 50 },
|
|
410
|
+
message: { expectedFields: 7, bloomBits: 128, avgChunkSize: 60 },
|
|
411
|
+
content: { expectedFields: 5, bloomBits: 128, avgChunkSize: 50 },
|
|
412
|
+
collection: { expectedFields: 4, bloomBits: 128, avgChunkSize: 40 },
|
|
413
|
+
dataset: { expectedFields: 6, bloomBits: 128, avgChunkSize: 50 },
|
|
414
|
+
product: { expectedFields: 8, bloomBits: 256, avgChunkSize: 70 },
|
|
415
|
+
service: { expectedFields: 7, bloomBits: 128, avgChunkSize: 60 },
|
|
416
|
+
user: { expectedFields: 9, bloomBits: 256, avgChunkSize: 80 },
|
|
417
|
+
task: { expectedFields: 6, bloomBits: 128, avgChunkSize: 50 },
|
|
418
|
+
project: { expectedFields: 8, bloomBits: 256, avgChunkSize: 70 },
|
|
419
|
+
process: { expectedFields: 5, bloomBits: 128, avgChunkSize: 50 },
|
|
420
|
+
state: { expectedFields: 3, bloomBits: 128, avgChunkSize: 30 },
|
|
421
|
+
role: { expectedFields: 4, bloomBits: 128, avgChunkSize: 40 },
|
|
422
|
+
topic: { expectedFields: 4, bloomBits: 128, avgChunkSize: 40 },
|
|
423
|
+
language: { expectedFields: 3, bloomBits: 128, avgChunkSize: 30 },
|
|
424
|
+
currency: { expectedFields: 3, bloomBits: 128, avgChunkSize: 30 },
|
|
425
|
+
measurement: { expectedFields: 4, bloomBits: 128, avgChunkSize: 40 },
|
|
426
|
+
hypothesis: { expectedFields: 6, bloomBits: 128, avgChunkSize: 50 },
|
|
427
|
+
experiment: { expectedFields: 7, bloomBits: 128, avgChunkSize: 60 },
|
|
428
|
+
contract: { expectedFields: 8, bloomBits: 256, avgChunkSize: 70 },
|
|
429
|
+
regulation: { expectedFields: 6, bloomBits: 128, avgChunkSize: 50 },
|
|
430
|
+
interface: { expectedFields: 5, bloomBits: 128, avgChunkSize: 50 },
|
|
431
|
+
resource: { expectedFields: 5, bloomBits: 128, avgChunkSize: 50 }
|
|
432
|
+
};
|
|
261
433
|
//# sourceMappingURL=graphTypes.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Automatically updates indexes when data changes
|
|
5
5
|
*/
|
|
6
6
|
import { StorageAdapter } from '../coreTypes.js';
|
|
7
|
-
import { NounType } from '../types/graphTypes.js';
|
|
7
|
+
import { NounType, VerbType } from '../types/graphTypes.js';
|
|
8
8
|
export interface MetadataIndexEntry {
|
|
9
9
|
field: string;
|
|
10
10
|
value: string | number | boolean;
|
|
@@ -66,11 +66,12 @@ export declare class MetadataIndexManager {
|
|
|
66
66
|
private readonly FLOAT_PRECISION;
|
|
67
67
|
private typeFieldAffinity;
|
|
68
68
|
private totalEntitiesByType;
|
|
69
|
+
private entityCountsByTypeFixed;
|
|
70
|
+
private verbCountsByTypeFixed;
|
|
69
71
|
private unifiedCache;
|
|
70
72
|
private activeLocks;
|
|
71
73
|
private lockPromises;
|
|
72
74
|
private lockTimers;
|
|
73
|
-
private sparseIndices;
|
|
74
75
|
private chunkManager;
|
|
75
76
|
private chunkingStrategy;
|
|
76
77
|
private idMapper;
|
|
@@ -80,6 +81,20 @@ export declare class MetadataIndexManager {
|
|
|
80
81
|
* This must be called after construction and before any queries
|
|
81
82
|
*/
|
|
82
83
|
init(): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Warm the cache by preloading common field sparse indices (v3.44.1)
|
|
86
|
+
* This improves cache hit rates by loading frequently-accessed fields at startup
|
|
87
|
+
* Target: >80% cache hit rate for typical workloads
|
|
88
|
+
*/
|
|
89
|
+
warmCache(): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Phase 1b: Warm cache for top types (type-aware optimization)
|
|
92
|
+
* Preloads metadata indices for the most common entity types and their top fields
|
|
93
|
+
* This significantly improves query performance for the most frequently accessed data
|
|
94
|
+
*
|
|
95
|
+
* @param topN Number of top types to warm (default: 3)
|
|
96
|
+
*/
|
|
97
|
+
warmCacheForTopTypes(topN?: number): Promise<void>;
|
|
83
98
|
/**
|
|
84
99
|
* Acquire an in-memory lock for coordinating concurrent metadata index writes
|
|
85
100
|
* Uses in-memory locks since MetadataIndexManager doesn't have direct file system access
|
|
@@ -100,6 +115,17 @@ export declare class MetadataIndexManager {
|
|
|
100
115
|
* This avoids rebuilding the entire index on startup
|
|
101
116
|
*/
|
|
102
117
|
private lazyLoadCounts;
|
|
118
|
+
/**
|
|
119
|
+
* Phase 1b: Sync Map-based counts to fixed-size Uint32Arrays
|
|
120
|
+
* This enables gradual migration from Maps to arrays while maintaining backward compatibility
|
|
121
|
+
* Called periodically and on demand to keep both representations in sync
|
|
122
|
+
*/
|
|
123
|
+
private syncTypeCountsToFixed;
|
|
124
|
+
/**
|
|
125
|
+
* Phase 1b: Sync from fixed-size arrays back to Maps (reverse direction)
|
|
126
|
+
* Used when Uint32Arrays are the source of truth and need to update Maps
|
|
127
|
+
*/
|
|
128
|
+
private syncTypeCountsFromFixed;
|
|
103
129
|
/**
|
|
104
130
|
* Update cardinality statistics for a field
|
|
105
131
|
*/
|
|
@@ -122,15 +148,18 @@ export declare class MetadataIndexManager {
|
|
|
122
148
|
private saveSparseIndex;
|
|
123
149
|
/**
|
|
124
150
|
* Get IDs for a value using chunked sparse index with roaring bitmaps (v3.43.0)
|
|
151
|
+
* v3.44.1: Now fully lazy-loaded via UnifiedCache (no local sparseIndices Map)
|
|
125
152
|
*/
|
|
126
153
|
private getIdsFromChunks;
|
|
127
154
|
/**
|
|
128
155
|
* Get IDs for a range using chunked sparse index with zone maps and roaring bitmaps (v3.43.0)
|
|
156
|
+
* v3.44.1: Now fully lazy-loaded via UnifiedCache (no local sparseIndices Map)
|
|
129
157
|
*/
|
|
130
158
|
private getIdsFromChunksForRange;
|
|
131
159
|
/**
|
|
132
160
|
* Get roaring bitmap for a field-value pair without converting to UUIDs (v3.43.0)
|
|
133
161
|
* This is used for fast multi-field intersection queries using hardware-accelerated bitmap AND
|
|
162
|
+
* v3.44.1: Now fully lazy-loaded via UnifiedCache (no local sparseIndices Map)
|
|
134
163
|
* @returns RoaringBitmap32 containing integer IDs, or null if no matches
|
|
135
164
|
*/
|
|
136
165
|
private getBitmapFromChunks;
|
|
@@ -155,10 +184,12 @@ export declare class MetadataIndexManager {
|
|
|
155
184
|
}>): Promise<string[]>;
|
|
156
185
|
/**
|
|
157
186
|
* Add value-ID mapping to chunked index
|
|
187
|
+
* v3.44.1: Now fully lazy-loaded via UnifiedCache (no local sparseIndices Map)
|
|
158
188
|
*/
|
|
159
189
|
private addToChunkedIndex;
|
|
160
190
|
/**
|
|
161
191
|
* Remove ID from chunked index
|
|
192
|
+
* v3.44.1: Now fully lazy-loaded via UnifiedCache (no local sparseIndices Map)
|
|
162
193
|
*/
|
|
163
194
|
private removeFromChunkedIndex;
|
|
164
195
|
/**
|
|
@@ -269,17 +300,57 @@ export declare class MetadataIndexManager {
|
|
|
269
300
|
* Get all entity types and their counts - O(1) operation
|
|
270
301
|
*/
|
|
271
302
|
getAllEntityCounts(): Map<string, number>;
|
|
303
|
+
/**
|
|
304
|
+
* Get entity count for a noun type using type enum (O(1) array access)
|
|
305
|
+
* More efficient than Map-based getEntityCountByType
|
|
306
|
+
* @param type Noun type from NounTypeEnum
|
|
307
|
+
* @returns Count of entities of this type
|
|
308
|
+
*/
|
|
309
|
+
getEntityCountByTypeEnum(type: NounType): number;
|
|
310
|
+
/**
|
|
311
|
+
* Get verb count for a verb type using type enum (O(1) array access)
|
|
312
|
+
* @param type Verb type from VerbTypeEnum
|
|
313
|
+
* @returns Count of verbs of this type
|
|
314
|
+
*/
|
|
315
|
+
getVerbCountByTypeEnum(type: VerbType): number;
|
|
316
|
+
/**
|
|
317
|
+
* Get top N noun types by entity count (using fixed-size arrays)
|
|
318
|
+
* Useful for type-aware cache warming and query optimization
|
|
319
|
+
* @param n Number of top types to return
|
|
320
|
+
* @returns Array of noun types sorted by count (highest first)
|
|
321
|
+
*/
|
|
322
|
+
getTopNounTypes(n: number): NounType[];
|
|
323
|
+
/**
|
|
324
|
+
* Get top N verb types by count (using fixed-size arrays)
|
|
325
|
+
* @param n Number of top types to return
|
|
326
|
+
* @returns Array of verb types sorted by count (highest first)
|
|
327
|
+
*/
|
|
328
|
+
getTopVerbTypes(n: number): VerbType[];
|
|
329
|
+
/**
|
|
330
|
+
* Get all noun type counts as a Map (using fixed-size arrays)
|
|
331
|
+
* More efficient than getAllEntityCounts for type-aware queries
|
|
332
|
+
* @returns Map of noun type to count
|
|
333
|
+
*/
|
|
334
|
+
getAllNounTypeCounts(): Map<NounType, number>;
|
|
335
|
+
/**
|
|
336
|
+
* Get all verb type counts as a Map (using fixed-size arrays)
|
|
337
|
+
* @returns Map of verb type to count
|
|
338
|
+
*/
|
|
339
|
+
getAllVerbTypeCounts(): Map<VerbType, number>;
|
|
272
340
|
/**
|
|
273
341
|
* Get count of entities matching field-value criteria - queries chunked sparse index
|
|
274
342
|
*/
|
|
275
343
|
getCountForCriteria(field: string, value: any): Promise<number>;
|
|
276
344
|
/**
|
|
277
345
|
* Get index statistics with enhanced counting information
|
|
346
|
+
* v3.44.1: Sparse indices now lazy-loaded via UnifiedCache
|
|
347
|
+
* Note: This method may load sparse indices to calculate stats
|
|
278
348
|
*/
|
|
279
349
|
getStats(): Promise<MetadataIndexStats>;
|
|
280
350
|
/**
|
|
281
351
|
* Rebuild entire index from scratch using pagination
|
|
282
352
|
* Non-blocking version that yields control back to event loop
|
|
353
|
+
* v3.44.1: Sparse indices now lazy-loaded via UnifiedCache (no need to clear Map)
|
|
283
354
|
*/
|
|
284
355
|
rebuild(): Promise<void>;
|
|
285
356
|
/**
|