@soulcraft/brainy 0.22.0 → 0.24.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.
@@ -8,19 +8,12 @@ import { NounType, VerbType } from './types/graphTypes.js';
8
8
  import { WebSocketConnection } from './types/augmentations.js';
9
9
  import { BrainyDataInterface } from './types/brainyDataInterface.js';
10
10
  export interface BrainyDataConfig {
11
- /**
12
- * Vector dimensions (required if not using an embedding function that auto-detects dimensions)
13
- */
14
- dimensions?: number;
15
11
  /**
16
12
  * HNSW index configuration
13
+ * Uses the optimized HNSW implementation which supports large datasets
14
+ * through product quantization and disk-based storage
17
15
  */
18
- hnsw?: Partial<HNSWConfig>;
19
- /**
20
- * Optimized HNSW index configuration
21
- * If provided, will use the optimized HNSW index instead of the standard one
22
- */
23
- hnswOptimized?: Partial<HNSWOptimizedConfig>;
16
+ hnsw?: Partial<HNSWOptimizedConfig>;
24
17
  /**
25
18
  * Distance function to use for similarity calculations
26
19
  */
@@ -403,6 +396,12 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
403
396
  * @private
404
397
  */
405
398
  private getNounCount;
399
+ /**
400
+ * Force an immediate flush of statistics to storage
401
+ * This ensures that any pending statistics updates are written to persistent storage
402
+ * @returns Promise that resolves when the statistics have been flushed
403
+ */
404
+ flushStatistics(): Promise<void>;
406
405
  /**
407
406
  * Get statistics about the current state of the database
408
407
  * @param options Additional options for retrieving statistics
@@ -193,4 +193,9 @@ export interface StorageAdapter {
193
193
  * @param size The new size of the HNSW index
194
194
  */
195
195
  updateHnswIndexSize(size: number): Promise<void>;
196
+ /**
197
+ * Force an immediate flush of statistics to storage
198
+ * This ensures that any pending statistics updates are written to persistent storage
199
+ */
200
+ flushStatisticsToStorage(): Promise<void>;
196
201
  }
@@ -74,6 +74,11 @@ export declare abstract class BaseStorageAdapter implements StorageAdapter {
74
74
  * @param size The new size of the HNSW index
75
75
  */
76
76
  updateHnswIndexSize(size: number): Promise<void>;
77
+ /**
78
+ * Force an immediate flush of statistics to storage
79
+ * This ensures that any pending statistics updates are written to persistent storage
80
+ */
81
+ flushStatisticsToStorage(): Promise<void>;
77
82
  /**
78
83
  * Create default statistics data
79
84
  * @returns Default statistics data
@@ -1 +1 @@
1
- {"version":3,"file":"baseStorageAdapter.d.ts","sourceRoot":"","sources":["../../../src/storage/adapters/baseStorageAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEnE;;GAEG;AACH,8BAAsB,kBAAmB,YAAW,cAAc;IAEhE,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;IACjD,QAAQ,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACtC,QAAQ,CAAC,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC7D,QAAQ,CAAC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAC9C,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;IACjD,QAAQ,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACtC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC3D,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OA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
  import { BaseStorage } from '../baseStorage.js';
7
- /**
8
- * Type alias for HNSWNoun to make the code more readable
9
- */
10
- type HNSWNoun_internal = HNSWNoun;
11
- /**
12
- * Type alias for GraphVerb to make the code more readable
13
- */
14
- type Verb = GraphVerb;
15
7
  /**
16
8
  * In-memory storage adapter
17
9
  * Uses Maps to store data in memory
@@ -30,21 +22,21 @@ export declare class MemoryStorage extends BaseStorage {
30
22
  /**
31
23
  * Save a noun to storage
32
24
  */
33
- protected saveNoun_internal(noun: HNSWNoun_internal): Promise<void>;
25
+ protected saveNoun_internal(noun: HNSWNoun): Promise<void>;
34
26
  /**
35
27
  * Get a noun from storage
36
28
  */
37
- protected getNoun_internal(id: string): Promise<HNSWNoun_internal | null>;
29
+ protected getNoun_internal(id: string): Promise<HNSWNoun | null>;
38
30
  /**
39
31
  * Get all nouns from storage
40
32
  */
41
- protected getAllNouns_internal(): Promise<HNSWNoun_internal[]>;
33
+ protected getAllNouns_internal(): Promise<HNSWNoun[]>;
42
34
  /**
43
35
  * Get nouns by noun type
44
36
  * @param nounType The noun type to filter by
45
37
  * @returns Promise that resolves to an array of nouns of the specified noun type
46
38
  */
47
- protected getNounsByNounType_internal(nounType: string): Promise<HNSWNoun_internal[]>;
39
+ protected getNounsByNounType_internal(nounType: string): Promise<HNSWNoun[]>;
48
40
  /**
49
41
  * Delete a noun from storage
50
42
  */
@@ -52,27 +44,27 @@ export declare class MemoryStorage extends BaseStorage {
52
44
  /**
53
45
  * Save a verb to storage
54
46
  */
55
- protected saveVerb_internal(verb: Verb): Promise<void>;
47
+ protected saveVerb_internal(verb: GraphVerb): Promise<void>;
56
48
  /**
57
49
  * Get a verb from storage
58
50
  */
59
- protected getVerb_internal(id: string): Promise<Verb | null>;
51
+ protected getVerb_internal(id: string): Promise<GraphVerb | null>;
60
52
  /**
61
53
  * Get all verbs from storage
62
54
  */
63
- protected getAllVerbs_internal(): Promise<Verb[]>;
55
+ protected getAllVerbs_internal(): Promise<GraphVerb[]>;
64
56
  /**
65
57
  * Get verbs by source
66
58
  */
67
- protected getVerbsBySource_internal(sourceId: string): Promise<Verb[]>;
59
+ protected getVerbsBySource_internal(sourceId: string): Promise<GraphVerb[]>;
68
60
  /**
69
61
  * Get verbs by target
70
62
  */
71
- protected getVerbsByTarget_internal(targetId: string): Promise<Verb[]>;
63
+ protected getVerbsByTarget_internal(targetId: string): Promise<GraphVerb[]>;
72
64
  /**
73
65
  * Get verbs by type
74
66
  */
75
- protected getVerbsByType_internal(type: string): Promise<Verb[]>;
67
+ protected getVerbsByType_internal(type: string): Promise<GraphVerb[]>;
76
68
  /**
77
69
  * Delete a verb from storage
78
70
  */
@@ -109,4 +101,3 @@ export declare class MemoryStorage extends BaseStorage {
109
101
  */
110
102
  protected getStatisticsData(): Promise<StatisticsData | null>;
111
103
  }
112
- export {};
@@ -1 +1 @@
1
- {"version":3,"file":"memoryStorage.d.ts","sourceRoot":"","sources":["../../../src/storage/adapters/memoryStorage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAA;AAE/D;;GAEG;AACH,KAAK,iBAAiB,GAAG,QAAQ,CAAA;AAEjC;;GAEG;AACH,KAAK,IAAI,GAAG,SAAS,CAAA;AAErB;;;GAGG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAE5C,OAAO,CAAC,KAAK,CAA4C;IACzD,OAAO,CAAC,KAAK,CAA+B;IAC5C,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,UAAU,CAA8B;;IAMhD;;;OAGG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC;;OAEG;cACa,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBzE;;OAEG;cACa,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,O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schedule a batch update instead of saving immediately
5406
5406
  this.scheduleBatchUpdate();
5407
5407
  }
5408
+ /**
5409
+ * Force an immediate flush of statistics to storage
5410
+ * This ensures that any pending statistics updates are written to persistent storage
5411
+ */
5412
+ async flushStatisticsToStorage() {
5413
+ // If there are no statistics in cache or they haven't been modified, nothing to flush
5414
+ if (!this.statisticsCache || !this.statisticsModified) {
5415
+ return;
5416
+ }
5417
+ // Call the protected flushStatistics method to immediately write to storage
5418
+ await this.flushStatistics();
5419
+ }
5408
5420
  /**
5409
5421
  * Create default statistics data
5410
5422
  * @returns Default statistics data
@@ -5549,6 +5561,7 @@ class BaseStorage extends BaseStorageAdapter {
5549
5561
  * Memory Storage Adapter
5550
5562
  * In-memory storage adapter for environments where persistent storage is not available or needed
5551
5563
  */
5564
+ // No type aliases needed - using the original types directly
5552
5565
  /**
5553
5566
  * In-memory storage adapter
5554
5567
  * Uses Maps to store data in memory
@@ -10861,24 +10874,13 @@ class BrainyData {
10861
10874
  this.remoteServerConfig = null;
10862
10875
  this.serverSearchConduit = null;
10863
10876
  this.serverConnection = null;
10864
- // Validate dimensions
10865
- if (config.dimensions !== undefined && config.dimensions <= 0) {
10866
- throw new Error('Dimensions must be a positive number');
10867
- }
10868
- // Set dimensions (default to 512 for embedding functions, or require explicit config)
10869
- this._dimensions = config.dimensions || 512;
10877
+ // Set dimensions to fixed value of 512 (Universal Sentence Encoder dimension)
10878
+ this._dimensions = 512;
10870
10879
  // Set distance function
10871
10880
  this.distanceFunction = config.distanceFunction || cosineDistance$1;
10872
- // Check if optimized HNSW index configuration is provided
10873
- if (config.hnswOptimized) {
10874
- // Initialize optimized HNSW index
10875
- this.index = new HNSWIndexOptimized(config.hnswOptimized, this.distanceFunction, config.storageAdapter || null);
10876
- this.useOptimizedIndex = true;
10877
- }
10878
- else {
10879
- // Initialize standard HNSW index
10880
- this.index = new HNSWIndex(config.hnsw, this.distanceFunction);
10881
- }
10881
+ // Always use the optimized HNSW index implementation
10882
+ this.index = new HNSWIndexOptimized(config.hnsw || {}, this.distanceFunction, config.storageAdapter || null);
10883
+ this.useOptimizedIndex = true;
10882
10884
  // Set storage if provided, otherwise it will be initialized in init()
10883
10885
  this.storage = config.storageAdapter || null;
10884
10886
  // Store logging configuration
@@ -11408,6 +11410,10 @@ class BrainyData {
11408
11410
  if (!queryVector) {
11409
11411
  throw new Error('Query vector is undefined or null');
11410
11412
  }
11413
+ // Check if query vector dimensions match the expected dimensions
11414
+ if (queryVector.length !== this._dimensions) {
11415
+ throw new Error(`Query vector dimension mismatch: expected ${this._dimensions}, got ${queryVector.length}`);
11416
+ }
11411
11417
  // If no noun types specified, search all nouns
11412
11418
  if (!nounTypes || nounTypes.length === 0) {
11413
11419
  // Search in the index
@@ -12144,6 +12150,19 @@ class BrainyData {
12144
12150
  }
12145
12151
  return nounCount;
12146
12152
  }
12153
+ /**
12154
+ * Force an immediate flush of statistics to storage
12155
+ * This ensures that any pending statistics updates are written to persistent storage
12156
+ * @returns Promise that resolves when the statistics have been flushed
12157
+ */
12158
+ async flushStatistics() {
12159
+ await this.ensureInitialized();
12160
+ if (!this.storage) {
12161
+ throw new Error('Storage not initialized');
12162
+ }
12163
+ // Call the flushStatisticsToStorage method on the storage adapter
12164
+ await this.storage.flushStatisticsToStorage();
12165
+ }
12147
12166
  /**
12148
12167
  * Get statistics about the current state of the database
12149
12168
  * @param options Additional options for retrieving statistics
@@ -12725,6 +12744,16 @@ class BrainyData {
12725
12744
  */
12726
12745
  async shutDown() {
12727
12746
  try {
12747
+ // Flush statistics to ensure they're saved before shutting down
12748
+ if (this.storage && this.isInitialized) {
12749
+ try {
12750
+ await this.flushStatistics();
12751
+ }
12752
+ catch (statsError) {
12753
+ console.warn('Failed to flush statistics during shutdown:', statsError);
12754
+ // Continue with shutdown even if statistics flush fails
12755
+ }
12756
+ }
12728
12757
  // Disconnect from remote server if connected
12729
12758
  if (this.isConnectedToRemoteServer()) {
12730
12759
  await this.disconnectFromRemoteServer();
@@ -12896,7 +12925,9 @@ class BrainyData {
12896
12925
  try {
12897
12926
  console.log('Reconstructing HNSW index from backup data...');
12898
12927
  // Create a new index with the restored configuration
12899
- this.index = new HNSWIndex(data.hnswIndex.config, this.distanceFunction);
12928
+ // Always use the optimized implementation for consistency
12929
+ this.index = new HNSWIndexOptimized(data.hnswIndex.config, this.distanceFunction, this.storage);
12930
+ this.useOptimizedIndex = true;
12900
12931
  // Re-add all nouns to the index
12901
12932
  for (const noun of data.nouns) {
12902
12933
  if (noun.vector && noun.vector.length > 0) {