@soulcraft/brainy 5.3.6 → 5.5.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 +110 -0
- package/README.md +4 -3
- package/dist/augmentations/display/fieldPatterns.js +3 -3
- package/dist/augmentations/display/intelligentComputation.js +0 -2
- package/dist/augmentations/typeMatching/brainyTypes.js +6 -8
- package/dist/brainy.d.ts +61 -0
- package/dist/brainy.js +180 -24
- package/dist/cortex/neuralImport.js +0 -1
- package/dist/importers/SmartExcelImporter.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/neural/embeddedKeywordEmbeddings.d.ts +1 -1
- package/dist/neural/embeddedKeywordEmbeddings.js +56 -56
- package/dist/neural/embeddedTypeEmbeddings.d.ts +3 -3
- package/dist/neural/embeddedTypeEmbeddings.js +14 -14
- package/dist/neural/entityExtractor.js +2 -2
- package/dist/neural/relationshipConfidence.js +1 -1
- package/dist/neural/signals/VerbContextSignal.js +6 -6
- package/dist/neural/signals/VerbExactMatchSignal.js +9 -9
- package/dist/neural/signals/VerbPatternSignal.js +5 -5
- package/dist/query/typeAwareQueryPlanner.js +2 -3
- package/dist/storage/adapters/azureBlobStorage.d.ts +13 -64
- package/dist/storage/adapters/azureBlobStorage.js +78 -388
- package/dist/storage/adapters/fileSystemStorage.d.ts +12 -78
- package/dist/storage/adapters/fileSystemStorage.js +49 -395
- package/dist/storage/adapters/gcsStorage.d.ts +13 -134
- package/dist/storage/adapters/gcsStorage.js +79 -557
- package/dist/storage/adapters/historicalStorageAdapter.d.ts +181 -0
- package/dist/storage/adapters/historicalStorageAdapter.js +332 -0
- package/dist/storage/adapters/memoryStorage.d.ts +4 -113
- package/dist/storage/adapters/memoryStorage.js +34 -471
- package/dist/storage/adapters/opfsStorage.d.ts +14 -127
- package/dist/storage/adapters/opfsStorage.js +44 -693
- package/dist/storage/adapters/r2Storage.d.ts +8 -41
- package/dist/storage/adapters/r2Storage.js +49 -237
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +13 -111
- package/dist/storage/adapters/s3CompatibleStorage.js +77 -596
- package/dist/storage/baseStorage.d.ts +78 -38
- package/dist/storage/baseStorage.js +692 -23
- package/dist/storage/cow/BlobStorage.d.ts +2 -2
- package/dist/storage/cow/BlobStorage.js +4 -4
- package/dist/storage/storageFactory.d.ts +2 -3
- package/dist/storage/storageFactory.js +114 -66
- package/dist/types/graphTypes.d.ts +588 -230
- package/dist/types/graphTypes.js +683 -248
- package/dist/types/typeMigration.d.ts +95 -0
- package/dist/types/typeMigration.js +141 -0
- package/dist/utils/intelligentTypeMapper.js +2 -2
- package/dist/utils/metadataIndex.js +6 -6
- package/dist/vfs/types.d.ts +6 -2
- package/package.json +2 -2
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Historical Storage Adapter
|
|
3
|
+
*
|
|
4
|
+
* Provides lazy-loading read-only access to a historical commit state.
|
|
5
|
+
* Uses LRU cache to bound memory usage and prevent eager-loading of entire history.
|
|
6
|
+
*
|
|
7
|
+
* Architecture:
|
|
8
|
+
* - Extends BaseStorage to inherit all storage infrastructure
|
|
9
|
+
* - Wraps an underlying storage adapter to access commit state
|
|
10
|
+
* - Implements lazy-loading with LRU cache (bounded memory)
|
|
11
|
+
* - All writes throw read-only errors
|
|
12
|
+
* - All reads load from historical commit state on-demand
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* const historical = new HistoricalStorageAdapter({
|
|
16
|
+
* underlyingStorage: brain.storage as BaseStorage,
|
|
17
|
+
* commitId: 'abc123...',
|
|
18
|
+
* cacheSize: 10000 // LRU cache size
|
|
19
|
+
* })
|
|
20
|
+
* await historical.init()
|
|
21
|
+
*
|
|
22
|
+
* Performance:
|
|
23
|
+
* - O(1) cache lookups for frequently accessed entities
|
|
24
|
+
* - Bounded memory: max cacheSize entities in memory
|
|
25
|
+
* - Lazy loading: only loads entities when accessed
|
|
26
|
+
* - No eager-loading of entire commit state
|
|
27
|
+
*
|
|
28
|
+
* v5.4.0: Production-ready, billion-scale historical queries
|
|
29
|
+
*/
|
|
30
|
+
import { BaseStorage } from '../baseStorage.js';
|
|
31
|
+
import { CommitLog } from '../cow/CommitLog.js';
|
|
32
|
+
import { TreeObject } from '../cow/TreeObject.js';
|
|
33
|
+
import { BlobStorage } from '../cow/BlobStorage.js';
|
|
34
|
+
import { HNSWNoun, HNSWVerb, NounMetadata, VerbMetadata, StatisticsData } from '../../coreTypes.js';
|
|
35
|
+
export interface HistoricalStorageAdapterOptions {
|
|
36
|
+
/** Underlying storage to access commit state from */
|
|
37
|
+
underlyingStorage: BaseStorage;
|
|
38
|
+
/** Commit ID to load historical state from */
|
|
39
|
+
commitId: string;
|
|
40
|
+
/** Max number of entities to cache (default: 10000) */
|
|
41
|
+
cacheSize?: number;
|
|
42
|
+
/** Branch containing the commit (default: 'main') */
|
|
43
|
+
branch?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Historical Storage Adapter
|
|
47
|
+
*
|
|
48
|
+
* Lazy-loading, read-only storage adapter for historical commit state.
|
|
49
|
+
* Implements billion-scale time-travel queries with bounded memory.
|
|
50
|
+
*/
|
|
51
|
+
export declare class HistoricalStorageAdapter extends BaseStorage {
|
|
52
|
+
private underlyingStorage;
|
|
53
|
+
private commitId;
|
|
54
|
+
private branch;
|
|
55
|
+
private cacheSize;
|
|
56
|
+
private cache;
|
|
57
|
+
commitLog?: CommitLog;
|
|
58
|
+
treeObject?: TreeObject;
|
|
59
|
+
blobStorage?: BlobStorage;
|
|
60
|
+
constructor(options: HistoricalStorageAdapterOptions);
|
|
61
|
+
/**
|
|
62
|
+
* Initialize historical storage adapter
|
|
63
|
+
* Loads commit metadata but NOT entity data (lazy loading)
|
|
64
|
+
*/
|
|
65
|
+
init(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Read object from historical commit state
|
|
68
|
+
* Uses LRU cache to avoid repeated blob reads
|
|
69
|
+
*/
|
|
70
|
+
protected readObjectFromPath(path: string): Promise<any | null>;
|
|
71
|
+
/**
|
|
72
|
+
* List objects under path in historical commit state
|
|
73
|
+
*/
|
|
74
|
+
protected listObjectsUnderPath(prefix: string): Promise<string[]>;
|
|
75
|
+
/**
|
|
76
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
77
|
+
*/
|
|
78
|
+
protected writeObjectToPath(path: string, data: any): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* DELETE BLOCKED: Historical storage is read-only
|
|
81
|
+
*/
|
|
82
|
+
protected deleteObjectFromPath(path: string): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Get storage statistics from historical commit
|
|
85
|
+
*/
|
|
86
|
+
protected getStatisticsData(): Promise<StatisticsData | null>;
|
|
87
|
+
/**
|
|
88
|
+
* WRITE BLOCKED: Cannot save statistics to historical storage
|
|
89
|
+
*/
|
|
90
|
+
protected saveStatisticsData(data: StatisticsData): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Clear cache (does not affect historical data)
|
|
93
|
+
*/
|
|
94
|
+
clear(): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Get storage status
|
|
97
|
+
*/
|
|
98
|
+
getStorageStatus(): Promise<{
|
|
99
|
+
type: string;
|
|
100
|
+
used: number;
|
|
101
|
+
quota: number | null;
|
|
102
|
+
details?: Record<string, any>;
|
|
103
|
+
}>;
|
|
104
|
+
/**
|
|
105
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
106
|
+
*/
|
|
107
|
+
saveNoun(noun: HNSWNoun): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
110
|
+
*/
|
|
111
|
+
saveNounMetadata(id: string, metadata: NounMetadata): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
114
|
+
*/
|
|
115
|
+
deleteNoun(id: string): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
118
|
+
*/
|
|
119
|
+
deleteNounMetadata(id: string): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
122
|
+
*/
|
|
123
|
+
saveVerb(verb: HNSWVerb): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
126
|
+
*/
|
|
127
|
+
saveVerbMetadata(id: string, metadata: VerbMetadata): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
130
|
+
*/
|
|
131
|
+
deleteVerb(id: string): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
134
|
+
*/
|
|
135
|
+
deleteVerbMetadata(id: string): Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
138
|
+
*/
|
|
139
|
+
saveMetadata(id: string, metadata: any): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
142
|
+
*/
|
|
143
|
+
saveHNSWData(nounId: string, hnswData: {
|
|
144
|
+
level: number;
|
|
145
|
+
connections: Record<string, string[]>;
|
|
146
|
+
}): Promise<void>;
|
|
147
|
+
/**
|
|
148
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
149
|
+
*/
|
|
150
|
+
saveHNSWSystem(systemData: {
|
|
151
|
+
entryPointId: string | null;
|
|
152
|
+
maxLevel: number;
|
|
153
|
+
}): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* Get noun vector from historical state
|
|
156
|
+
*/
|
|
157
|
+
getNounVector(id: string): Promise<number[] | null>;
|
|
158
|
+
/**
|
|
159
|
+
* Get HNSW data from historical state
|
|
160
|
+
*/
|
|
161
|
+
getHNSWData(nounId: string): Promise<{
|
|
162
|
+
level: number;
|
|
163
|
+
connections: Record<string, string[]>;
|
|
164
|
+
} | null>;
|
|
165
|
+
/**
|
|
166
|
+
* Get HNSW system data from historical state
|
|
167
|
+
*/
|
|
168
|
+
getHNSWSystem(): Promise<{
|
|
169
|
+
entryPointId: string | null;
|
|
170
|
+
maxLevel: number;
|
|
171
|
+
} | null>;
|
|
172
|
+
/**
|
|
173
|
+
* Initialize counts (no-op for historical storage)
|
|
174
|
+
* Counts are loaded from historical state metadata
|
|
175
|
+
*/
|
|
176
|
+
protected initializeCounts(): Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* WRITE BLOCKED: Cannot persist counts to historical storage
|
|
179
|
+
*/
|
|
180
|
+
protected persistCounts(): Promise<void>;
|
|
181
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Historical Storage Adapter
|
|
3
|
+
*
|
|
4
|
+
* Provides lazy-loading read-only access to a historical commit state.
|
|
5
|
+
* Uses LRU cache to bound memory usage and prevent eager-loading of entire history.
|
|
6
|
+
*
|
|
7
|
+
* Architecture:
|
|
8
|
+
* - Extends BaseStorage to inherit all storage infrastructure
|
|
9
|
+
* - Wraps an underlying storage adapter to access commit state
|
|
10
|
+
* - Implements lazy-loading with LRU cache (bounded memory)
|
|
11
|
+
* - All writes throw read-only errors
|
|
12
|
+
* - All reads load from historical commit state on-demand
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* const historical = new HistoricalStorageAdapter({
|
|
16
|
+
* underlyingStorage: brain.storage as BaseStorage,
|
|
17
|
+
* commitId: 'abc123...',
|
|
18
|
+
* cacheSize: 10000 // LRU cache size
|
|
19
|
+
* })
|
|
20
|
+
* await historical.init()
|
|
21
|
+
*
|
|
22
|
+
* Performance:
|
|
23
|
+
* - O(1) cache lookups for frequently accessed entities
|
|
24
|
+
* - Bounded memory: max cacheSize entities in memory
|
|
25
|
+
* - Lazy loading: only loads entities when accessed
|
|
26
|
+
* - No eager-loading of entire commit state
|
|
27
|
+
*
|
|
28
|
+
* v5.4.0: Production-ready, billion-scale historical queries
|
|
29
|
+
*/
|
|
30
|
+
import { BaseStorage } from '../baseStorage.js';
|
|
31
|
+
/**
|
|
32
|
+
* Simple LRU Cache implementation
|
|
33
|
+
* Bounds memory usage by evicting least-recently-used items
|
|
34
|
+
*/
|
|
35
|
+
class LRUCache {
|
|
36
|
+
constructor(maxSize = 10000) {
|
|
37
|
+
this.cache = new Map();
|
|
38
|
+
this.accessOrder = [];
|
|
39
|
+
this.maxSize = maxSize;
|
|
40
|
+
}
|
|
41
|
+
get(key) {
|
|
42
|
+
const value = this.cache.get(key);
|
|
43
|
+
if (value !== undefined) {
|
|
44
|
+
// Move to end (most recently used)
|
|
45
|
+
this.accessOrder = this.accessOrder.filter(k => k !== key);
|
|
46
|
+
this.accessOrder.push(key);
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
set(key, value) {
|
|
51
|
+
// Remove if already exists
|
|
52
|
+
if (this.cache.has(key)) {
|
|
53
|
+
this.accessOrder = this.accessOrder.filter(k => k !== key);
|
|
54
|
+
}
|
|
55
|
+
// Add to cache
|
|
56
|
+
this.cache.set(key, value);
|
|
57
|
+
this.accessOrder.push(key);
|
|
58
|
+
// Evict oldest if over capacity
|
|
59
|
+
if (this.cache.size > this.maxSize) {
|
|
60
|
+
const oldest = this.accessOrder.shift();
|
|
61
|
+
if (oldest) {
|
|
62
|
+
this.cache.delete(oldest);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
has(key) {
|
|
67
|
+
return this.cache.has(key);
|
|
68
|
+
}
|
|
69
|
+
clear() {
|
|
70
|
+
this.cache.clear();
|
|
71
|
+
this.accessOrder = [];
|
|
72
|
+
}
|
|
73
|
+
get size() {
|
|
74
|
+
return this.cache.size;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Historical Storage Adapter
|
|
79
|
+
*
|
|
80
|
+
* Lazy-loading, read-only storage adapter for historical commit state.
|
|
81
|
+
* Implements billion-scale time-travel queries with bounded memory.
|
|
82
|
+
*/
|
|
83
|
+
export class HistoricalStorageAdapter extends BaseStorage {
|
|
84
|
+
constructor(options) {
|
|
85
|
+
super();
|
|
86
|
+
this.underlyingStorage = options.underlyingStorage;
|
|
87
|
+
this.commitId = options.commitId;
|
|
88
|
+
this.branch = options.branch || 'main';
|
|
89
|
+
this.cacheSize = options.cacheSize || 10000;
|
|
90
|
+
this.cache = new LRUCache(this.cacheSize);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Initialize historical storage adapter
|
|
94
|
+
* Loads commit metadata but NOT entity data (lazy loading)
|
|
95
|
+
*/
|
|
96
|
+
async init() {
|
|
97
|
+
// Get COW components from underlying storage
|
|
98
|
+
this.commitLog = this.underlyingStorage._commitLog;
|
|
99
|
+
this.treeObject = this.underlyingStorage._treeObject;
|
|
100
|
+
this.blobStorage = this.underlyingStorage._blobStorage;
|
|
101
|
+
if (!this.commitLog || !this.treeObject || !this.blobStorage) {
|
|
102
|
+
throw new Error('Historical storage requires underlying storage to have COW enabled. ' +
|
|
103
|
+
'Call brain.init() first to initialize COW.');
|
|
104
|
+
}
|
|
105
|
+
// Verify commit exists
|
|
106
|
+
const commit = await this.commitLog.getCommit(this.commitId);
|
|
107
|
+
if (!commit) {
|
|
108
|
+
throw new Error(`Commit not found: ${this.commitId}`);
|
|
109
|
+
}
|
|
110
|
+
// Mark as initialized
|
|
111
|
+
this.isInitialized = true;
|
|
112
|
+
}
|
|
113
|
+
// ============= Abstract Method Implementations =============
|
|
114
|
+
/**
|
|
115
|
+
* Read object from historical commit state
|
|
116
|
+
* Uses LRU cache to avoid repeated blob reads
|
|
117
|
+
*/
|
|
118
|
+
async readObjectFromPath(path) {
|
|
119
|
+
// Check cache first
|
|
120
|
+
if (this.cache.has(path)) {
|
|
121
|
+
return this.cache.get(path) || null;
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
// Import COW classes
|
|
125
|
+
const { CommitObject } = await import('../cow/CommitObject.js');
|
|
126
|
+
const { TreeObject } = await import('../cow/TreeObject.js');
|
|
127
|
+
const { isNullHash } = await import('../cow/constants.js');
|
|
128
|
+
// Read commit
|
|
129
|
+
const commit = await CommitObject.read(this.blobStorage, this.commitId);
|
|
130
|
+
if (isNullHash(commit.tree)) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
// Read tree
|
|
134
|
+
const tree = await TreeObject.read(this.blobStorage, commit.tree);
|
|
135
|
+
// Walk tree to find matching path
|
|
136
|
+
for await (const entry of TreeObject.walk(this.blobStorage, tree)) {
|
|
137
|
+
if (entry.type === 'blob' && entry.name === path) {
|
|
138
|
+
// Read blob data
|
|
139
|
+
const blobData = await this.blobStorage.read(entry.hash);
|
|
140
|
+
const data = JSON.parse(blobData.toString());
|
|
141
|
+
// Cache the result
|
|
142
|
+
this.cache.set(path, data);
|
|
143
|
+
return data;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
// Path doesn't exist in historical state
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* List objects under path in historical commit state
|
|
155
|
+
*/
|
|
156
|
+
async listObjectsUnderPath(prefix) {
|
|
157
|
+
try {
|
|
158
|
+
// Import COW classes
|
|
159
|
+
const { CommitObject } = await import('../cow/CommitObject.js');
|
|
160
|
+
const { TreeObject } = await import('../cow/TreeObject.js');
|
|
161
|
+
const { isNullHash } = await import('../cow/constants.js');
|
|
162
|
+
// Read commit
|
|
163
|
+
const commit = await CommitObject.read(this.blobStorage, this.commitId);
|
|
164
|
+
if (isNullHash(commit.tree)) {
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
// Read tree
|
|
168
|
+
const tree = await TreeObject.read(this.blobStorage, commit.tree);
|
|
169
|
+
// Walk tree to find all paths matching prefix
|
|
170
|
+
const paths = [];
|
|
171
|
+
for await (const entry of TreeObject.walk(this.blobStorage, tree)) {
|
|
172
|
+
if (entry.name.startsWith(prefix)) {
|
|
173
|
+
paths.push(entry.name);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return paths;
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
184
|
+
*/
|
|
185
|
+
async writeObjectToPath(path, data) {
|
|
186
|
+
throw new Error(`Historical storage is read-only. Cannot write to path: ${path}`);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* DELETE BLOCKED: Historical storage is read-only
|
|
190
|
+
*/
|
|
191
|
+
async deleteObjectFromPath(path) {
|
|
192
|
+
throw new Error(`Historical storage is read-only. Cannot delete path: ${path}`);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Get storage statistics from historical commit
|
|
196
|
+
*/
|
|
197
|
+
async getStatisticsData() {
|
|
198
|
+
return await this.readObjectFromPath('_system/statistics.json');
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* WRITE BLOCKED: Cannot save statistics to historical storage
|
|
202
|
+
*/
|
|
203
|
+
async saveStatisticsData(data) {
|
|
204
|
+
throw new Error('Historical storage is read-only. Cannot save statistics.');
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Clear cache (does not affect historical data)
|
|
208
|
+
*/
|
|
209
|
+
async clear() {
|
|
210
|
+
this.cache.clear();
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Get storage status
|
|
214
|
+
*/
|
|
215
|
+
async getStorageStatus() {
|
|
216
|
+
return {
|
|
217
|
+
type: 'historical',
|
|
218
|
+
used: this.cache.size,
|
|
219
|
+
quota: this.cacheSize,
|
|
220
|
+
details: {
|
|
221
|
+
commitId: this.commitId,
|
|
222
|
+
branch: this.branch,
|
|
223
|
+
cached: this.cache.size,
|
|
224
|
+
maxCache: this.cacheSize,
|
|
225
|
+
readOnly: true
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
// ============= Override Write Methods (Read-Only) =============
|
|
230
|
+
/**
|
|
231
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
232
|
+
*/
|
|
233
|
+
async saveNoun(noun) {
|
|
234
|
+
throw new Error('Historical storage is read-only. Cannot save noun.');
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
238
|
+
*/
|
|
239
|
+
async saveNounMetadata(id, metadata) {
|
|
240
|
+
throw new Error('Historical storage is read-only. Cannot save noun metadata.');
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
244
|
+
*/
|
|
245
|
+
async deleteNoun(id) {
|
|
246
|
+
throw new Error('Historical storage is read-only. Cannot delete noun.');
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
250
|
+
*/
|
|
251
|
+
async deleteNounMetadata(id) {
|
|
252
|
+
throw new Error('Historical storage is read-only. Cannot delete noun metadata.');
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
256
|
+
*/
|
|
257
|
+
async saveVerb(verb) {
|
|
258
|
+
throw new Error('Historical storage is read-only. Cannot save verb.');
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
262
|
+
*/
|
|
263
|
+
async saveVerbMetadata(id, metadata) {
|
|
264
|
+
throw new Error('Historical storage is read-only. Cannot save verb metadata.');
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
268
|
+
*/
|
|
269
|
+
async deleteVerb(id) {
|
|
270
|
+
throw new Error('Historical storage is read-only. Cannot delete verb.');
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
274
|
+
*/
|
|
275
|
+
async deleteVerbMetadata(id) {
|
|
276
|
+
throw new Error('Historical storage is read-only. Cannot delete verb metadata.');
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
280
|
+
*/
|
|
281
|
+
async saveMetadata(id, metadata) {
|
|
282
|
+
throw new Error('Historical storage is read-only. Cannot save metadata.');
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
286
|
+
*/
|
|
287
|
+
async saveHNSWData(nounId, hnswData) {
|
|
288
|
+
throw new Error('Historical storage is read-only. Cannot save HNSW data.');
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* WRITE BLOCKED: Historical storage is read-only
|
|
292
|
+
*/
|
|
293
|
+
async saveHNSWSystem(systemData) {
|
|
294
|
+
throw new Error('Historical storage is read-only. Cannot save HNSW system data.');
|
|
295
|
+
}
|
|
296
|
+
// ============= Additional Abstract Methods =============
|
|
297
|
+
/**
|
|
298
|
+
* Get noun vector from historical state
|
|
299
|
+
*/
|
|
300
|
+
async getNounVector(id) {
|
|
301
|
+
const noun = await this.getNoun(id);
|
|
302
|
+
return noun?.vector || null;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Get HNSW data from historical state
|
|
306
|
+
*/
|
|
307
|
+
async getHNSWData(nounId) {
|
|
308
|
+
const path = `_system/hnsw/nodes/${nounId}.json`;
|
|
309
|
+
return await this.readObjectFromPath(path);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Get HNSW system data from historical state
|
|
313
|
+
*/
|
|
314
|
+
async getHNSWSystem() {
|
|
315
|
+
return await this.readObjectFromPath('_system/hnsw/system.json');
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Initialize counts (no-op for historical storage)
|
|
319
|
+
* Counts are loaded from historical state metadata
|
|
320
|
+
*/
|
|
321
|
+
async initializeCounts() {
|
|
322
|
+
// No-op: Historical storage doesn't need to initialize counts
|
|
323
|
+
// They're read from commit state metadata
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* WRITE BLOCKED: Cannot persist counts to historical storage
|
|
327
|
+
*/
|
|
328
|
+
async persistCounts() {
|
|
329
|
+
// No-op: Historical storage is read-only
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
//# sourceMappingURL=historicalStorageAdapter.js.map
|
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
* Memory Storage Adapter
|
|
3
3
|
* In-memory storage adapter for environments where persistent storage is not available or needed
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { StatisticsData } from '../../coreTypes.js';
|
|
6
6
|
import { BaseStorage, StorageBatchConfig } from '../baseStorage.js';
|
|
7
7
|
/**
|
|
8
8
|
* In-memory storage adapter
|
|
9
9
|
* Uses Maps to store data in memory
|
|
10
10
|
*/
|
|
11
11
|
export declare class MemoryStorage extends BaseStorage {
|
|
12
|
-
private nouns;
|
|
13
|
-
private verbs;
|
|
14
12
|
private statistics;
|
|
15
13
|
private objectStore;
|
|
16
14
|
private get metadata();
|
|
@@ -35,122 +33,12 @@ export declare class MemoryStorage extends BaseStorage {
|
|
|
35
33
|
* Nothing to initialize for in-memory storage
|
|
36
34
|
*/
|
|
37
35
|
init(): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Save a noun to storage (v4.0.0: pure vector only, no metadata)
|
|
40
|
-
* v5.0.1: COW-aware - uses branch-prefixed paths for fork isolation
|
|
41
|
-
*/
|
|
42
|
-
protected saveNoun_internal(noun: HNSWNoun): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Get a noun from storage (v4.0.0: returns pure vector only)
|
|
45
|
-
* Base class handles combining with metadata
|
|
46
|
-
* v5.0.1: COW-aware - reads from branch-prefixed paths with inheritance
|
|
47
|
-
*/
|
|
48
|
-
protected getNoun_internal(id: string): Promise<HNSWNoun | null>;
|
|
49
36
|
/**
|
|
50
37
|
* Get nouns with pagination and filtering
|
|
51
38
|
* v4.0.0: Returns HNSWNounWithMetadata[] (includes metadata field)
|
|
52
39
|
* @param options Pagination and filtering options
|
|
53
40
|
* @returns Promise that resolves to a paginated result of nouns with metadata
|
|
54
41
|
*/
|
|
55
|
-
getNouns(options?: {
|
|
56
|
-
pagination?: {
|
|
57
|
-
offset?: number;
|
|
58
|
-
limit?: number;
|
|
59
|
-
cursor?: string;
|
|
60
|
-
};
|
|
61
|
-
filter?: {
|
|
62
|
-
nounType?: string | string[];
|
|
63
|
-
service?: string | string[];
|
|
64
|
-
metadata?: Record<string, any>;
|
|
65
|
-
};
|
|
66
|
-
}): Promise<{
|
|
67
|
-
items: HNSWNounWithMetadata[];
|
|
68
|
-
totalCount?: number;
|
|
69
|
-
hasMore: boolean;
|
|
70
|
-
nextCursor?: string;
|
|
71
|
-
}>;
|
|
72
|
-
/**
|
|
73
|
-
* Get nouns with pagination - simplified interface for compatibility
|
|
74
|
-
* v4.0.0: Returns HNSWNounWithMetadata[] (includes metadata field)
|
|
75
|
-
*/
|
|
76
|
-
getNounsWithPagination(options?: {
|
|
77
|
-
limit?: number;
|
|
78
|
-
cursor?: string;
|
|
79
|
-
filter?: any;
|
|
80
|
-
}): Promise<{
|
|
81
|
-
items: HNSWNounWithMetadata[];
|
|
82
|
-
totalCount: number;
|
|
83
|
-
hasMore: boolean;
|
|
84
|
-
nextCursor?: string;
|
|
85
|
-
}>;
|
|
86
|
-
/**
|
|
87
|
-
* Get nouns by noun type
|
|
88
|
-
* @param nounType The noun type to filter by
|
|
89
|
-
* @returns Promise that resolves to an array of nouns of the specified noun type
|
|
90
|
-
* @deprecated Use getNouns() with filter.nounType instead
|
|
91
|
-
*/
|
|
92
|
-
protected getNounsByNounType_internal(nounType: string): Promise<HNSWNoun[]>;
|
|
93
|
-
/**
|
|
94
|
-
* Delete a noun from storage (v4.0.0)
|
|
95
|
-
* v5.0.1: COW-aware - deletes from branch-prefixed paths
|
|
96
|
-
*/
|
|
97
|
-
protected deleteNoun_internal(id: string): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Save a verb to storage (v4.0.0: pure vector + core fields, no metadata)
|
|
100
|
-
* v5.0.1: COW-aware - uses branch-prefixed paths for fork isolation
|
|
101
|
-
*/
|
|
102
|
-
protected saveVerb_internal(verb: HNSWVerb): Promise<void>;
|
|
103
|
-
/**
|
|
104
|
-
* Get a verb from storage (v4.0.0: returns pure vector + core fields)
|
|
105
|
-
* Base class handles combining with metadata
|
|
106
|
-
* v5.0.1: COW-aware - reads from branch-prefixed paths with inheritance
|
|
107
|
-
*/
|
|
108
|
-
protected getVerb_internal(id: string): Promise<HNSWVerb | null>;
|
|
109
|
-
/**
|
|
110
|
-
* Get verbs with pagination and filtering
|
|
111
|
-
* v4.0.0: Returns HNSWVerbWithMetadata[] (includes metadata field)
|
|
112
|
-
* @param options Pagination and filtering options
|
|
113
|
-
* @returns Promise that resolves to a paginated result of verbs with metadata
|
|
114
|
-
*/
|
|
115
|
-
getVerbs(options?: {
|
|
116
|
-
pagination?: {
|
|
117
|
-
offset?: number;
|
|
118
|
-
limit?: number;
|
|
119
|
-
cursor?: string;
|
|
120
|
-
};
|
|
121
|
-
filter?: {
|
|
122
|
-
verbType?: string | string[];
|
|
123
|
-
sourceId?: string | string[];
|
|
124
|
-
targetId?: string | string[];
|
|
125
|
-
service?: string | string[];
|
|
126
|
-
metadata?: Record<string, any>;
|
|
127
|
-
};
|
|
128
|
-
}): Promise<{
|
|
129
|
-
items: HNSWVerbWithMetadata[];
|
|
130
|
-
totalCount?: number;
|
|
131
|
-
hasMore: boolean;
|
|
132
|
-
nextCursor?: string;
|
|
133
|
-
}>;
|
|
134
|
-
/**
|
|
135
|
-
* Get verbs by source
|
|
136
|
-
* @deprecated Use getVerbs() with filter.sourceId instead
|
|
137
|
-
*/
|
|
138
|
-
protected getVerbsBySource_internal(sourceId: string): Promise<HNSWVerbWithMetadata[]>;
|
|
139
|
-
/**
|
|
140
|
-
* Get verbs by target
|
|
141
|
-
* @deprecated Use getVerbs() with filter.targetId instead
|
|
142
|
-
*/
|
|
143
|
-
protected getVerbsByTarget_internal(targetId: string): Promise<HNSWVerbWithMetadata[]>;
|
|
144
|
-
/**
|
|
145
|
-
* Get verbs by type
|
|
146
|
-
* @deprecated Use getVerbs() with filter.verbType instead
|
|
147
|
-
*/
|
|
148
|
-
protected getVerbsByType_internal(type: string): Promise<HNSWVerbWithMetadata[]>;
|
|
149
|
-
/**
|
|
150
|
-
* Delete a verb from storage
|
|
151
|
-
* v5.0.1: COW-aware - deletes from branch-prefixed paths
|
|
152
|
-
*/
|
|
153
|
-
protected deleteVerb_internal(id: string): Promise<void>;
|
|
154
42
|
/**
|
|
155
43
|
* Primitive operation: Write object to path
|
|
156
44
|
* All metadata operations use this internally via base class routing
|
|
@@ -178,10 +66,12 @@ export declare class MemoryStorage extends BaseStorage {
|
|
|
178
66
|
getMetadataBatch(ids: string[]): Promise<Map<string, any>>;
|
|
179
67
|
/**
|
|
180
68
|
* Clear all data from storage
|
|
69
|
+
* v5.4.0: Clears objectStore (type-first paths)
|
|
181
70
|
*/
|
|
182
71
|
clear(): Promise<void>;
|
|
183
72
|
/**
|
|
184
73
|
* Get information about storage usage and capacity
|
|
74
|
+
* v5.4.0: Uses BaseStorage counts
|
|
185
75
|
*/
|
|
186
76
|
getStorageStatus(): Promise<{
|
|
187
77
|
type: string;
|
|
@@ -209,6 +99,7 @@ export declare class MemoryStorage extends BaseStorage {
|
|
|
209
99
|
protected persistCounts(): Promise<void>;
|
|
210
100
|
/**
|
|
211
101
|
* Get vector for a noun
|
|
102
|
+
* v5.4.0: Uses BaseStorage's type-first implementation
|
|
212
103
|
*/
|
|
213
104
|
getNounVector(id: string): Promise<number[] | null>;
|
|
214
105
|
private hnswLocks;
|