@soulcraft/brainy 5.4.0 → 5.6.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +4 -3
  3. package/dist/augmentations/display/fieldPatterns.js +3 -3
  4. package/dist/augmentations/display/intelligentComputation.d.ts +1 -1
  5. package/dist/augmentations/display/intelligentComputation.js +1 -3
  6. package/dist/augmentations/typeMatching/brainyTypes.d.ts +1 -1
  7. package/dist/augmentations/typeMatching/brainyTypes.js +7 -9
  8. package/dist/augmentations/typeMatching/intelligentTypeMatcher.d.ts +1 -1
  9. package/dist/augmentations/typeMatching/intelligentTypeMatcher.js +1 -1
  10. package/dist/augmentations/universalDisplayAugmentation.d.ts +1 -1
  11. package/dist/augmentations/universalDisplayAugmentation.js +1 -1
  12. package/dist/brainy.js +2 -2
  13. package/dist/cli/commands/types.js +2 -2
  14. package/dist/cortex/neuralImport.js +0 -1
  15. package/dist/hnsw/typeAwareHNSWIndex.d.ts +3 -3
  16. package/dist/hnsw/typeAwareHNSWIndex.js +5 -5
  17. package/dist/importers/SmartExcelImporter.js +2 -2
  18. package/dist/index.d.ts +2 -2
  19. package/dist/neural/embeddedKeywordEmbeddings.d.ts +1 -1
  20. package/dist/neural/embeddedKeywordEmbeddings.js +56 -56
  21. package/dist/neural/embeddedTypeEmbeddings.d.ts +3 -3
  22. package/dist/neural/embeddedTypeEmbeddings.js +14 -14
  23. package/dist/neural/entityExtractor.js +2 -2
  24. package/dist/neural/relationshipConfidence.js +1 -1
  25. package/dist/neural/signals/VerbContextSignal.js +6 -6
  26. package/dist/neural/signals/VerbExactMatchSignal.js +9 -9
  27. package/dist/neural/signals/VerbPatternSignal.js +5 -5
  28. package/dist/query/typeAwareQueryPlanner.d.ts +7 -7
  29. package/dist/query/typeAwareQueryPlanner.js +9 -10
  30. package/dist/storage/baseStorage.d.ts +48 -1
  31. package/dist/storage/baseStorage.js +237 -19
  32. package/dist/types/graphTypes.d.ts +588 -230
  33. package/dist/types/graphTypes.js +683 -248
  34. package/dist/types/typeMigration.d.ts +95 -0
  35. package/dist/types/typeMigration.js +141 -0
  36. package/dist/utils/intelligentTypeMapper.js +2 -2
  37. package/dist/utils/metadataIndex.js +6 -6
  38. package/package.json +2 -2
  39. package/dist/importManager.d.ts +0 -78
  40. package/dist/importManager.js +0 -267
  41. package/dist/storage/adapters/typeAwareStorageAdapter.d.ts +0 -300
  42. package/dist/storage/adapters/typeAwareStorageAdapter.js +0 -1012
@@ -1,300 +0,0 @@
1
- /**
2
- * Type-Aware Storage Adapter
3
- *
4
- * Wraps underlying storage (FileSystem, GCS, S3, etc.) with type-first organization.
5
- * Enables efficient type-based queries via directory structure.
6
- *
7
- * IMPLEMENTED Features (v3.45.0):
8
- * - Type-first paths: entities/nouns/{type}/vectors/{shard}/{uuid}.json
9
- * - Fixed-size type count tracking: Uint32Array(31 + 40) = 284 bytes
10
- * - Type-based filtering: List entities by type via directory structure
11
- * - Type caching: Map<id, type> for frequently accessed entities
12
- *
13
- * MEASURED Performance (tests up to 1M entities):
14
- * - Type count memory: 284 bytes (vs Map-based: ~100KB at 1M scale) = 99.7% reduction
15
- * - getNounsByType: O(entities_of_type) via directory scan (vs O(total) full scan)
16
- * - getVerbsByType: O(entities_of_type) via directory scan (vs O(total) full scan)
17
- * - Type-cached lookups: O(1) after first access
18
- *
19
- * PROJECTED Performance (billion-scale, NOT tested):
20
- * - Total memory: PROJECTED ~50-100GB (vs theoretical 500GB baseline)
21
- * - Type count: 284 bytes remains constant (not dependent on entity count)
22
- * - Type cache: Grows with usage (10% cached at 1B = ~5GB overhead)
23
- * - Note: Billion-scale claims are EXTRAPOLATIONS, not measurements
24
- *
25
- * LIMITATIONS:
26
- * - Type cache grows unbounded (no eviction policy)
27
- * - Uncached entity lookups: O(types) worst case (searches all type directories)
28
- * - v4.8.1: getVerbsBySource/Target delegate to underlying (previously O(total_verbs))
29
- *
30
- * TEST COVERAGE:
31
- * - Unit tests: typeAwareStorageAdapter.test.ts (17 tests passing)
32
- * - Integration tests: Tested with 1,155 entities (Workshop data)
33
- * - Performance tests: None (no benchmark comparisons yet)
34
- *
35
- * @version 3.45.0 (created), 4.8.1 (performance fix)
36
- * @since Phase 1 - Type-First Implementation
37
- */
38
- import { BaseStorage } from '../baseStorage.js';
39
- import { HNSWNoun, HNSWVerb, HNSWNounWithMetadata, HNSWVerbWithMetadata, NounMetadata, VerbMetadata, StatisticsData } from '../../coreTypes.js';
40
- import { NounType, VerbType } from '../../types/graphTypes.js';
41
- /**
42
- * Options for TypeAwareStorageAdapter
43
- */
44
- export interface TypeAwareStorageOptions {
45
- /**
46
- * Underlying storage adapter to delegate file operations to
47
- * (e.g., FileSystemStorage, S3CompatibleStorage, MemoryStorage)
48
- */
49
- underlyingStorage: BaseStorage;
50
- /**
51
- * Optional: Enable verbose logging for debugging
52
- */
53
- verbose?: boolean;
54
- }
55
- /**
56
- * Type-Aware Storage Adapter
57
- *
58
- * Wraps an underlying storage adapter and adds type-first routing
59
- * Tracks types with fixed-size arrays for billion-scale efficiency
60
- */
61
- export declare class TypeAwareStorageAdapter extends BaseStorage {
62
- private underlying;
63
- private verbose;
64
- private nounCountsByType;
65
- private verbCountsByType;
66
- private nounTypeCache;
67
- private verbTypeCache;
68
- constructor(options: TypeAwareStorageOptions);
69
- /**
70
- * Helper to access protected methods on underlying storage
71
- * TypeScript doesn't allow calling protected methods across instances,
72
- * so we cast to any to bypass this restriction
73
- */
74
- private get u();
75
- /**
76
- * Initialize storage adapter
77
- */
78
- init(): Promise<void>;
79
- /**
80
- * Load type statistics from storage
81
- * Rebuilds type counts if needed
82
- */
83
- private loadTypeStatistics;
84
- /**
85
- * Save type statistics to storage
86
- */
87
- private saveTypeStatistics;
88
- /**
89
- * Get noun type from cache
90
- *
91
- * v4.0.0: Metadata is stored separately, so we rely on the cache
92
- * which is populated when saveNounMetadata is called
93
- */
94
- private getNounType;
95
- /**
96
- * Get verb type from verb object
97
- *
98
- * ARCHITECTURAL FIX (v3.50.1): Simplified - verb field is now always present
99
- */
100
- private getVerbType;
101
- /**
102
- * Save noun (type-first path)
103
- */
104
- protected saveNoun_internal(noun: HNSWNoun): Promise<void>;
105
- /**
106
- * Get noun (type-first path)
107
- */
108
- protected getNoun_internal(id: string): Promise<HNSWNoun | null>;
109
- /**
110
- * Get nouns by noun type (O(1) with type-first paths!)
111
- */
112
- protected getNounsByNounType_internal(nounType: string): Promise<HNSWNoun[]>;
113
- /**
114
- * Delete noun (type-first path)
115
- */
116
- protected deleteNoun_internal(id: string): Promise<void>;
117
- /**
118
- * Save verb (type-first path)
119
- *
120
- * ARCHITECTURAL FIX (v3.50.1): No more caching hack needed!
121
- * HNSWVerb now includes verb field, so type is always available
122
- */
123
- protected saveVerb_internal(verb: HNSWVerb): Promise<void>;
124
- /**
125
- * Get verb (type-first path)
126
- *
127
- * ARCHITECTURAL FIX (v3.50.1): Cache still useful for performance
128
- * Once we know where a verb is, we can retrieve it O(1) instead of searching all types
129
- */
130
- protected getVerb_internal(id: string): Promise<HNSWVerb | null>;
131
- /**
132
- * Get verbs by source
133
- */
134
- protected getVerbsBySource_internal(sourceId: string): Promise<HNSWVerbWithMetadata[]>;
135
- /**
136
- * Get verbs by target
137
- */
138
- protected getVerbsByTarget_internal(targetId: string): Promise<HNSWVerbWithMetadata[]>;
139
- /**
140
- * Get verbs by type (O(1) with type-first paths!)
141
- *
142
- * v4.0.0: Load verbs and combine with metadata
143
- */
144
- protected getVerbsByType_internal(verbType: string): Promise<HNSWVerbWithMetadata[]>;
145
- /**
146
- * Delete verb (type-first path)
147
- */
148
- protected deleteVerb_internal(id: string): Promise<void>;
149
- /**
150
- * Save noun metadata (override to cache type for type-aware routing)
151
- *
152
- * v4.0.0: Extract and cache noun type when metadata is saved
153
- */
154
- saveNounMetadata(id: string, metadata: NounMetadata): Promise<void>;
155
- /**
156
- * Get noun metadata (override to use type-aware paths)
157
- */
158
- getNounMetadata(id: string): Promise<NounMetadata | null>;
159
- /**
160
- * Delete noun metadata (override to use type-aware paths)
161
- */
162
- deleteNounMetadata(id: string): Promise<void>;
163
- /**
164
- * Save verb metadata (override to use type-aware paths)
165
- *
166
- * Note: Verb type comes from HNSWVerb.verb field, not metadata
167
- * We need to read the verb to get the type for path routing
168
- */
169
- saveVerbMetadata(id: string, metadata: VerbMetadata): Promise<void>;
170
- /**
171
- * Get verb metadata (override to use type-aware paths)
172
- */
173
- getVerbMetadata(id: string): Promise<VerbMetadata | null>;
174
- /**
175
- * Delete verb metadata (override to use type-aware paths)
176
- */
177
- deleteVerbMetadata(id: string): Promise<void>;
178
- /**
179
- * Write object to path (delegate to underlying storage)
180
- */
181
- protected writeObjectToPath(path: string, data: any): Promise<void>;
182
- /**
183
- * Read object from path (delegate to underlying storage)
184
- */
185
- protected readObjectFromPath(path: string): Promise<any | null>;
186
- /**
187
- * Delete object from path (delegate to underlying storage)
188
- */
189
- protected deleteObjectFromPath(path: string): Promise<void>;
190
- /**
191
- * List objects under path (delegate to underlying storage)
192
- */
193
- protected listObjectsUnderPath(prefix: string): Promise<string[]>;
194
- /**
195
- * Save statistics data
196
- */
197
- protected saveStatisticsData(statistics: StatisticsData): Promise<void>;
198
- /**
199
- * Get statistics data
200
- */
201
- protected getStatisticsData(): Promise<StatisticsData | null>;
202
- /**
203
- * Clear all data
204
- */
205
- clear(): Promise<void>;
206
- /**
207
- * Get storage status
208
- */
209
- getStorageStatus(): Promise<{
210
- type: string;
211
- used: number;
212
- quota: number | null;
213
- details?: Record<string, any>;
214
- }>;
215
- /**
216
- * Initialize counts from storage
217
- */
218
- protected initializeCounts(): Promise<void>;
219
- /**
220
- * Persist counts to storage
221
- */
222
- protected persistCounts(): Promise<void>;
223
- /**
224
- * Get noun vector (delegate to underlying storage)
225
- */
226
- getNounVector(id: string): Promise<number[] | null>;
227
- /**
228
- * Save HNSW data for a noun
229
- */
230
- saveHNSWData(nounId: string, hnswData: {
231
- level: number;
232
- connections: Record<string, string[]>;
233
- }): Promise<void>;
234
- /**
235
- * Get HNSW data for a noun
236
- */
237
- getHNSWData(nounId: string): Promise<{
238
- level: number;
239
- connections: Record<string, string[]>;
240
- } | null>;
241
- /**
242
- * Get nouns with pagination (v5.0.1: COW-aware)
243
- * Required for find() to work with TypeAwareStorage
244
- */
245
- getNounsWithPagination(options: {
246
- limit?: number;
247
- offset?: number;
248
- cursor?: string;
249
- filter?: any;
250
- }): Promise<{
251
- items: HNSWNounWithMetadata[];
252
- totalCount: number;
253
- hasMore: boolean;
254
- nextCursor?: string;
255
- }>;
256
- /**
257
- * Get verbs with pagination (v5.0.1: COW-aware)
258
- * Required for GraphAdjacencyIndex rebuild and find() to work
259
- */
260
- getVerbsWithPagination(options: {
261
- limit?: number;
262
- offset?: number;
263
- cursor?: string;
264
- filter?: any;
265
- }): Promise<{
266
- items: HNSWVerbWithMetadata[];
267
- totalCount: number;
268
- hasMore: boolean;
269
- nextCursor?: string;
270
- }>;
271
- /**
272
- * Save HNSW system data (entry point, max level)
273
- */
274
- saveHNSWSystem(systemData: {
275
- entryPointId: string | null;
276
- maxLevel: number;
277
- }): Promise<void>;
278
- /**
279
- * Get HNSW system data
280
- */
281
- getHNSWSystem(): Promise<{
282
- entryPointId: string | null;
283
- maxLevel: number;
284
- } | null>;
285
- /**
286
- * Get type statistics
287
- * Useful for analytics and optimization
288
- */
289
- getTypeStatistics(): {
290
- nouns: Array<{
291
- type: NounType;
292
- count: number;
293
- }>;
294
- verbs: Array<{
295
- type: VerbType;
296
- count: number;
297
- }>;
298
- totalMemory: number;
299
- };
300
- }