@soulcraft/brainy 0.48.0 → 0.50.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/README.md +304 -555
- package/dist/brainyData.d.ts +83 -2
- package/dist/brainyData.js +536 -66
- package/dist/brainyData.js.map +1 -1
- package/dist/coreTypes.d.ts +74 -12
- package/dist/distributed/configManager.d.ts +9 -0
- package/dist/distributed/configManager.js +129 -10
- package/dist/distributed/configManager.js.map +1 -1
- package/dist/hnsw/hnswIndex.d.ts +1 -1
- package/dist/hnsw/hnswIndex.js +44 -25
- package/dist/hnsw/hnswIndex.js.map +1 -1
- package/dist/hnsw/optimizedHNSWIndex.d.ts +1 -1
- package/dist/hnsw/optimizedHNSWIndex.js +3 -3
- package/dist/hnsw/optimizedHNSWIndex.js.map +1 -1
- package/dist/storage/adapters/baseStorageAdapter.d.ts +18 -2
- package/dist/storage/adapters/baseStorageAdapter.js +69 -4
- package/dist/storage/adapters/baseStorageAdapter.js.map +1 -1
- package/dist/storage/adapters/fileSystemStorage.d.ts +14 -8
- package/dist/storage/adapters/fileSystemStorage.js +90 -22
- package/dist/storage/adapters/fileSystemStorage.js.map +1 -1
- package/dist/storage/adapters/memoryStorage.d.ts +0 -8
- package/dist/storage/adapters/memoryStorage.js +26 -45
- package/dist/storage/adapters/memoryStorage.js.map +1 -1
- package/dist/storage/adapters/opfsStorage.d.ts +40 -8
- package/dist/storage/adapters/opfsStorage.js +195 -44
- package/dist/storage/adapters/opfsStorage.js.map +1 -1
- package/dist/storage/adapters/optimizedS3Search.js +4 -3
- package/dist/storage/adapters/optimizedS3Search.js.map +1 -1
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +3 -10
- package/dist/storage/adapters/s3CompatibleStorage.js +41 -44
- package/dist/storage/adapters/s3CompatibleStorage.js.map +1 -1
- package/dist/storage/backwardCompatibility.d.ts +84 -0
- package/dist/storage/backwardCompatibility.js +141 -0
- package/dist/storage/backwardCompatibility.js.map +1 -0
- package/dist/storage/baseStorage.d.ts +33 -19
- package/dist/storage/baseStorage.js +116 -195
- package/dist/storage/baseStorage.js.map +1 -1
- package/dist/utils/metadataFilter.d.ts +79 -0
- package/dist/utils/metadataFilter.js +229 -0
- package/dist/utils/metadataFilter.js.map +1 -0
- package/dist/utils/metadataIndex.d.ts +148 -0
- package/dist/utils/metadataIndex.js +639 -0
- package/dist/utils/metadataIndex.js.map +1 -0
- package/dist/utils/metadataIndexCache.d.ts +60 -0
- package/dist/utils/metadataIndexCache.js +119 -0
- package/dist/utils/metadataIndexCache.js.map +1 -0
- package/package.json +1 -1
package/dist/brainyData.d.ts
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
* BrainyData
|
|
3
3
|
* Main class that provides the vector database functionality
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { HNSWIndex } from './hnsw/hnswIndex.js';
|
|
6
|
+
import { HNSWIndexOptimized, HNSWOptimizedConfig } from './hnsw/hnswIndexOptimized.js';
|
|
6
7
|
import { DistanceFunction, GraphVerb, EmbeddingFunction, HNSWConfig, SearchResult, SearchCursor, PaginatedSearchResult, StorageAdapter, Vector, VectorDocument } from './coreTypes.js';
|
|
8
|
+
import { MetadataIndexManager, MetadataIndexConfig } from './utils/metadataIndex.js';
|
|
7
9
|
import { NounType, VerbType } from './types/graphTypes.js';
|
|
8
10
|
import { WebSocketConnection } from './types/augmentations.js';
|
|
9
11
|
import { BrainyDataInterface } from './types/brainyDataInterface.js';
|
|
@@ -80,8 +82,16 @@ export interface BrainyDataConfig {
|
|
|
80
82
|
/**
|
|
81
83
|
* Set the database to read-only mode
|
|
82
84
|
* When true, all write operations will throw an error
|
|
85
|
+
* Note: Statistics and index optimizations are still allowed unless frozen is also true
|
|
83
86
|
*/
|
|
84
87
|
readOnly?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Completely freeze the database, preventing all changes including statistics and index optimizations
|
|
90
|
+
* When true, the database is completely immutable (no data changes, no index rebalancing, no statistics updates)
|
|
91
|
+
* This is useful for forensic analysis, testing with deterministic state, or compliance scenarios
|
|
92
|
+
* Default: false (allows optimizations even in readOnly mode)
|
|
93
|
+
*/
|
|
94
|
+
frozen?: boolean;
|
|
85
95
|
/**
|
|
86
96
|
* Enable lazy loading in read-only mode
|
|
87
97
|
* When true and in read-only mode, the index is not fully loaded during initialization
|
|
@@ -123,6 +133,10 @@ export interface BrainyDataConfig {
|
|
|
123
133
|
*/
|
|
124
134
|
verbose?: boolean;
|
|
125
135
|
};
|
|
136
|
+
/**
|
|
137
|
+
* Metadata indexing configuration
|
|
138
|
+
*/
|
|
139
|
+
metadataIndex?: MetadataIndexConfig;
|
|
126
140
|
/**
|
|
127
141
|
* Search result caching configuration
|
|
128
142
|
* Improves performance for repeated queries
|
|
@@ -276,17 +290,20 @@ export interface BrainyDataConfig {
|
|
|
276
290
|
};
|
|
277
291
|
}
|
|
278
292
|
export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
279
|
-
|
|
293
|
+
index: HNSWIndex | HNSWIndexOptimized;
|
|
280
294
|
private storage;
|
|
295
|
+
metadataIndex: MetadataIndexManager | null;
|
|
281
296
|
private isInitialized;
|
|
282
297
|
private isInitializing;
|
|
283
298
|
private embeddingFunction;
|
|
284
299
|
private distanceFunction;
|
|
285
300
|
private requestPersistentStorage;
|
|
286
301
|
private readOnly;
|
|
302
|
+
private frozen;
|
|
287
303
|
private lazyLoadInReadOnlyMode;
|
|
288
304
|
private writeOnly;
|
|
289
305
|
private storageConfig;
|
|
306
|
+
private config;
|
|
290
307
|
private useOptimizedIndex;
|
|
291
308
|
private _dimensions;
|
|
292
309
|
private loggingConfig;
|
|
@@ -298,6 +315,7 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
298
315
|
private cacheConfig;
|
|
299
316
|
private realtimeUpdateConfig;
|
|
300
317
|
private updateTimerId;
|
|
318
|
+
private maintenanceIntervals;
|
|
301
319
|
private lastUpdateTime;
|
|
302
320
|
private lastKnownNounCount;
|
|
303
321
|
private remoteServerConfig;
|
|
@@ -331,6 +349,11 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
331
349
|
* @throws Error if the database is in read-only mode
|
|
332
350
|
*/
|
|
333
351
|
private checkReadOnly;
|
|
352
|
+
/**
|
|
353
|
+
* Check if the database is frozen and throw an error if it is
|
|
354
|
+
* @throws Error if the database is frozen
|
|
355
|
+
*/
|
|
356
|
+
private checkFrozen;
|
|
334
357
|
/**
|
|
335
358
|
* Check if the database is in write-only mode and throw an error if it is
|
|
336
359
|
* @param allowExistenceChecks If true, allows existence checks (get operations) in write-only mode
|
|
@@ -356,6 +379,10 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
356
379
|
* @param config Configuration for real-time updates
|
|
357
380
|
*/
|
|
358
381
|
enableRealtimeUpdates(config?: Partial<BrainyDataConfig['realtimeUpdates']>): void;
|
|
382
|
+
/**
|
|
383
|
+
* Start metadata index maintenance
|
|
384
|
+
*/
|
|
385
|
+
private startMetadataIndexMaintenance;
|
|
359
386
|
/**
|
|
360
387
|
* Disable real-time updates
|
|
361
388
|
*/
|
|
@@ -510,6 +537,7 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
510
537
|
searchByNounTypes(queryVectorOrData: Vector | any, k?: number, nounTypes?: string[] | null, options?: {
|
|
511
538
|
forceEmbed?: boolean;
|
|
512
539
|
service?: string;
|
|
540
|
+
metadata?: any;
|
|
513
541
|
offset?: number;
|
|
514
542
|
}): Promise<SearchResult<T>[]>;
|
|
515
543
|
/**
|
|
@@ -533,6 +561,7 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
533
561
|
filter?: {
|
|
534
562
|
domain?: string;
|
|
535
563
|
};
|
|
564
|
+
metadata?: any;
|
|
536
565
|
offset?: number;
|
|
537
566
|
skipCache?: boolean;
|
|
538
567
|
}): Promise<SearchResult<T>[]>;
|
|
@@ -572,6 +601,7 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
572
601
|
filter?: {
|
|
573
602
|
domain?: string;
|
|
574
603
|
};
|
|
604
|
+
metadata?: any;
|
|
575
605
|
offset?: number;
|
|
576
606
|
skipCache?: boolean;
|
|
577
607
|
}): Promise<SearchResult<T>[]>;
|
|
@@ -828,6 +858,17 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
828
858
|
};
|
|
829
859
|
};
|
|
830
860
|
}>;
|
|
861
|
+
/**
|
|
862
|
+
* List all services that have written data to the database
|
|
863
|
+
* @returns Array of service statistics
|
|
864
|
+
*/
|
|
865
|
+
listServices(): Promise<import('./coreTypes.js').ServiceStatistics[]>;
|
|
866
|
+
/**
|
|
867
|
+
* Get statistics for a specific service
|
|
868
|
+
* @param service The service name to get statistics for
|
|
869
|
+
* @returns Service statistics or null if service not found
|
|
870
|
+
*/
|
|
871
|
+
getServiceStatistics(service: string): Promise<import('./coreTypes.js').ServiceStatistics | null>;
|
|
831
872
|
/**
|
|
832
873
|
* Check if the database is in read-only mode
|
|
833
874
|
* @returns True if the database is in read-only mode, false otherwise
|
|
@@ -838,6 +879,17 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
838
879
|
* @param readOnly True to set the database to read-only mode, false to allow writes
|
|
839
880
|
*/
|
|
840
881
|
setReadOnly(readOnly: boolean): void;
|
|
882
|
+
/**
|
|
883
|
+
* Check if the database is frozen (completely immutable)
|
|
884
|
+
* @returns True if the database is frozen, false otherwise
|
|
885
|
+
*/
|
|
886
|
+
isFrozen(): boolean;
|
|
887
|
+
/**
|
|
888
|
+
* Set the database to frozen mode (completely immutable)
|
|
889
|
+
* When frozen, no changes are allowed including statistics updates and index optimizations
|
|
890
|
+
* @param frozen True to freeze the database, false to allow optimizations
|
|
891
|
+
*/
|
|
892
|
+
setFrozen(frozen: boolean): void;
|
|
841
893
|
/**
|
|
842
894
|
* Check if the database is in write-only mode
|
|
843
895
|
* @returns True if the database is in write-only mode, false otherwise
|
|
@@ -896,6 +948,34 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
896
948
|
verbTypes?: string[];
|
|
897
949
|
direction?: 'outgoing' | 'incoming' | 'both';
|
|
898
950
|
}): Promise<SearchResult<T>[]>;
|
|
951
|
+
/**
|
|
952
|
+
* Get available filter values for a field
|
|
953
|
+
* Useful for building dynamic filter UIs
|
|
954
|
+
*
|
|
955
|
+
* @param field The field name to get values for
|
|
956
|
+
* @returns Array of available values for that field
|
|
957
|
+
*/
|
|
958
|
+
getFilterValues(field: string): Promise<string[]>;
|
|
959
|
+
/**
|
|
960
|
+
* Get all available filter fields
|
|
961
|
+
* Useful for discovering what metadata fields are indexed
|
|
962
|
+
*
|
|
963
|
+
* @returns Array of indexed field names
|
|
964
|
+
*/
|
|
965
|
+
getFilterFields(): Promise<string[]>;
|
|
966
|
+
/**
|
|
967
|
+
* Search within a specific set of items
|
|
968
|
+
* This is useful when you've pre-filtered items and want to search only within them
|
|
969
|
+
*
|
|
970
|
+
* @param queryVectorOrData Query vector or data to search for
|
|
971
|
+
* @param itemIds Array of item IDs to search within
|
|
972
|
+
* @param k Number of results to return
|
|
973
|
+
* @param options Additional options
|
|
974
|
+
* @returns Array of search results
|
|
975
|
+
*/
|
|
976
|
+
searchWithinItems(queryVectorOrData: Vector | any, itemIds: string[], k?: number, options?: {
|
|
977
|
+
forceEmbed?: boolean;
|
|
978
|
+
}): Promise<SearchResult<T>[]>;
|
|
899
979
|
/**
|
|
900
980
|
* Search for similar documents using a text query
|
|
901
981
|
* This is a convenience method that embeds the query text and performs a search
|
|
@@ -909,6 +989,7 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
909
989
|
nounTypes?: string[];
|
|
910
990
|
includeVerbs?: boolean;
|
|
911
991
|
searchMode?: 'local' | 'remote' | 'combined';
|
|
992
|
+
metadata?: any;
|
|
912
993
|
}): Promise<SearchResult<T>[]>;
|
|
913
994
|
/**
|
|
914
995
|
* Search a remote Brainy server for similar vectors
|