@soulcraft/brainy 0.37.0 → 0.39.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.
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Intelligent cache auto-configuration system
3
+ * Adapts cache settings based on environment, usage patterns, and storage type
4
+ */
5
+ import { SearchCacheConfig } from './searchCache.js';
6
+ import { BrainyDataConfig } from '../brainyData.js';
7
+ export interface CacheUsageStats {
8
+ totalQueries: number;
9
+ repeatQueries: number;
10
+ avgQueryTime: number;
11
+ memoryPressure: number;
12
+ storageType: 'memory' | 'opfs' | 's3' | 'filesystem';
13
+ isDistributed: boolean;
14
+ changeFrequency: number;
15
+ readWriteRatio: number;
16
+ }
17
+ export interface AutoConfigResult {
18
+ cacheConfig: SearchCacheConfig;
19
+ realtimeConfig: NonNullable<BrainyDataConfig['realtimeUpdates']>;
20
+ reasoning: string[];
21
+ }
22
+ export declare class CacheAutoConfigurator {
23
+ private stats;
24
+ private configHistory;
25
+ private lastOptimization;
26
+ /**
27
+ * Auto-detect optimal cache configuration based on current conditions
28
+ */
29
+ autoDetectOptimalConfig(storageConfig?: BrainyDataConfig['storage'], currentStats?: Partial<CacheUsageStats>): AutoConfigResult;
30
+ /**
31
+ * Dynamically adjust configuration based on runtime performance
32
+ */
33
+ adaptConfiguration(currentConfig: SearchCacheConfig, performanceMetrics: {
34
+ hitRate: number;
35
+ avgResponseTime: number;
36
+ memoryUsage: number;
37
+ externalChangesDetected: number;
38
+ timeSinceLastChange: number;
39
+ }): AutoConfigResult | null;
40
+ /**
41
+ * Get recommended configuration for specific use case
42
+ */
43
+ getRecommendedConfig(useCase: 'high-consistency' | 'balanced' | 'performance-first'): AutoConfigResult;
44
+ /**
45
+ * Learn from usage patterns and improve recommendations
46
+ */
47
+ learnFromUsage(usageData: {
48
+ queryPatterns: string[];
49
+ responseTime: number;
50
+ cacheHits: number;
51
+ totalQueries: number;
52
+ dataChanges: number;
53
+ timeWindow: number;
54
+ }): void;
55
+ private detectEnvironment;
56
+ private generateOptimalConfig;
57
+ private calculateRealtimeConfig;
58
+ private detectMemoryConstraints;
59
+ /**
60
+ * Get human-readable explanation of current configuration
61
+ */
62
+ getConfigExplanation(config: AutoConfigResult): string;
63
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheAutoConfig.d.ts","sourceRoot":"","sources":["../../src/utils/cacheAutoConfig.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAEnD,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,GAAG,YAAY,CAAA;IACpD,aAAa,EAAE,OAAO,CAAA;IACtB,eAAe,EAAE,MAAM,CAAA;IACvB,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,iBAAiB,CAAA;IAC9B,cAAc,EAAE,WAAW,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAAA;IAChE,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,qBAAa,qBAAqB;IAChC,OAAO,CAAC,KAAK,CASZ;IAED,OAAO,CAAC,aAAa,CAAyB;IAC9C,OAAO,CAAC,gBAAgB,CAAI;IAE5B;;OAEG;IACI,uBAAuB,CAC5B,aAAa,CAAC,EAAE,gBAAgB,CAAC,SAAS,CAAC,EAC3C,YAAY,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GACtC,gBAAgB;IAmBnB;;OAEG;IACI,kBAAkB,CACvB,aAAa,EAAE,iBAAiB,EAChC,kBAAkB,EAAE;QAClB,OAAO,EAAE,MAAM,CAAA;QACf,eAAe,EAAE,MAAM,CAAA;QACvB,WAAW,EAAE,MAAM,CAAA;QACnB,uBAAuB,EAAE,MAAM,CAAA;QAC/B,mBAAmB,EAAE,MAAM,CAAA;KAC5B,GACA,gBAAgB,GAAG,IAAI;IAgE1B;;OAEG;IACI,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,GAAG,UAAU,GAAG,mBAAmB,GAAG,gBAAgB;IAkC7G;;OAEG;IACI,cAAc,CAAC,SAAS,EAAE;QAC/B,aAAa,EAAE,MAAM,EAAE,CAAA;QACvB,YAAY,EAAE,MAAM,CAAA;QACpB,SAAS,EAAE,MAAM,CAAA;QACjB,YAAY,EAAE,MAAM,CAAA;QACpB,WAAW,EAAE,MAAM,CAAA;QACnB,UAAU,EAAE,MAAM,CAAA;KACnB,GAAG,IAAI;IAaR,OAAO,CAAC,iBAAiB;IAmBzB,OAAO,CAAC,qBAAqB;IAkE7B,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,uBAAuB;IAe/B;;OAEG;IACI,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM;CAgB9D"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Cross-platform crypto utilities
3
+ * Provides hashing functions that work in both Node.js and browser environments
4
+ */
5
+ /**
6
+ * Simple string hash function that works in all environments
7
+ * Uses djb2 algorithm - fast and good distribution
8
+ * @param str - String to hash
9
+ * @returns Positive integer hash
10
+ */
11
+ export declare function hashString(str: string): number;
12
+ /**
13
+ * Alternative: FNV-1a hash algorithm
14
+ * Good distribution and fast
15
+ * @param str - String to hash
16
+ * @returns Positive integer hash
17
+ */
18
+ export declare function fnv1aHash(str: string): number;
19
+ /**
20
+ * Generate a deterministic hash for partitioning
21
+ * Uses the most appropriate algorithm for the environment
22
+ * @param input - Input string to hash
23
+ * @returns Positive integer hash suitable for modulo operations
24
+ */
25
+ export declare function getPartitionHash(input: string): number;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ9C;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO7C;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAItD"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * SearchCache - Caches search results for improved performance
3
+ */
4
+ import { SearchResult } from '../coreTypes.js';
5
+ export interface CacheEntry<T = any> {
6
+ results: SearchResult<T>[];
7
+ timestamp: number;
8
+ hits: number;
9
+ }
10
+ export interface SearchCacheConfig {
11
+ maxAge?: number;
12
+ maxSize?: number;
13
+ enabled?: boolean;
14
+ hitCountWeight?: number;
15
+ }
16
+ export declare class SearchCache<T = any> {
17
+ private cache;
18
+ private maxAge;
19
+ private maxSize;
20
+ private enabled;
21
+ private hitCountWeight;
22
+ private hits;
23
+ private misses;
24
+ private evictions;
25
+ constructor(config?: SearchCacheConfig);
26
+ /**
27
+ * Generate cache key from search parameters
28
+ */
29
+ getCacheKey(query: any, k: number, options?: Record<string, any>): string;
30
+ /**
31
+ * Get cached results if available and not expired
32
+ */
33
+ get(key: string): SearchResult<T>[] | null;
34
+ /**
35
+ * Cache search results
36
+ */
37
+ set(key: string, results: SearchResult<T>[]): void;
38
+ /**
39
+ * Evict the oldest entry based on timestamp and hit count
40
+ */
41
+ private evictOldest;
42
+ /**
43
+ * Clear all cached results
44
+ */
45
+ clear(): void;
46
+ /**
47
+ * Invalidate cache entries that might be affected by data changes
48
+ */
49
+ invalidate(pattern?: string | RegExp): void;
50
+ /**
51
+ * Smart invalidation for real-time data updates
52
+ * Only clears cache if it's getting stale or if data changes significantly
53
+ */
54
+ invalidateOnDataChange(changeType?: 'add' | 'update' | 'delete'): void;
55
+ /**
56
+ * Check if cache entries have expired and remove them
57
+ * This is especially important in distributed scenarios where
58
+ * real-time updates might be delayed or missed
59
+ */
60
+ cleanupExpiredEntries(): number;
61
+ /**
62
+ * Get cache statistics
63
+ */
64
+ getStats(): {
65
+ hits: number;
66
+ misses: number;
67
+ evictions: number;
68
+ hitRate: number;
69
+ size: number;
70
+ maxSize: number;
71
+ enabled: boolean;
72
+ };
73
+ /**
74
+ * Enable or disable caching
75
+ */
76
+ setEnabled(enabled: boolean): void;
77
+ /**
78
+ * Get memory usage estimate in bytes
79
+ */
80
+ getMemoryUsage(): number;
81
+ /**
82
+ * Get current cache configuration
83
+ */
84
+ getConfig(): SearchCacheConfig;
85
+ /**
86
+ * Update cache configuration dynamically
87
+ */
88
+ updateConfig(newConfig: Partial<SearchCacheConfig>): void;
89
+ /**
90
+ * Evict entries if cache exceeds maxSize
91
+ */
92
+ private evictIfNeeded;
93
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"searchCache.d.ts","sourceRoot":"","sources":["../../src/utils/searchCache.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,GAAG;IACjC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,qBAAa,WAAW,CAAC,CAAC,GAAG,GAAG;IAC9B,OAAO,CAAC,KAAK,CAAmC;IAChD,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAQ;IAG9B,OAAO,CAAC,IAAI,CAAI;IAChB,OAAO,CAAC,MAAM,CAAI;IAClB,OAAO,CAAC,SAAS,CAAI;gBAET,MAAM,GAAE,iBAAsB;IAO1C;;OAEG;IACH,WAAW,CACT,KAAK,EAAE,GAAG,EACV,CAAC,EAAE,MAAM,EACT,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAChC,MAAM;IAkBT;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI;IAsB1C;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI;IAelD;;OAEG;IACH,OAAO,CAAC,WAAW;IAwBnB;;OAEG;IACH,KAAK,IAAI,IAAI;IAOb;;OAEG;IACH,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAqB3C;;;OAGG;IACH,sBAAsB,CAAC,UAAU,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,IAAI;IAOtE;;;;OAIG;IACH,qBAAqB,IAAI,MAAM;IAc/B;;OAEG;IACH,QAAQ;;;;;;;;;IAaR;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAOlC;;OAEG;IACH,cAAc,IAAI,MAAM;IAexB;;OAEG;IACH,SAAS,IAAI,iBAAiB;IAS9B;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI;IAmBzD;;OAEG;IACH,OAAO,CAAC,aAAa;CA6BtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soulcraft/brainy",
3
- "version": "0.37.0",
3
+ "version": "0.39.0",
4
4
  "description": "A vector graph database using HNSW indexing with Origin Private File System storage",
5
5
  "main": "dist/unified.js",
6
6
  "module": "dist/unified.js",