@soulcraft/brainy 0.60.0 → 0.61.1
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 +7 -5
- package/bin/brainy.js +66 -80
- package/dist/augmentations/memoryAugmentations.js +32 -22
- package/dist/brainyData.d.ts +18 -8
- package/dist/brainyData.js +140 -74
- package/dist/coreTypes.d.ts +0 -12
- package/dist/cortex/cortex.js +5 -5
- package/dist/storage/adapters/baseStorageAdapter.d.ts +0 -12
- package/dist/storage/adapters/opfsStorage.js +26 -20
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +0 -12
- package/dist/storage/adapters/s3CompatibleStorage.js +70 -40
- package/dist/storage/baseStorage.d.ts +6 -8
- package/dist/storage/baseStorage.js +12 -20
- package/package.json +5 -5
|
@@ -381,15 +381,23 @@ export class S3CompatibleStorage extends BaseStorage {
|
|
|
381
381
|
// Get metrics
|
|
382
382
|
const backpressureStatus = this.backpressure.getStatus();
|
|
383
383
|
const socketMetrics = this.socketManager.getMetrics();
|
|
384
|
-
//
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
384
|
+
// Reasonable high-volume detection - only activate under real load
|
|
385
|
+
const isTestEnvironment = process.env.NODE_ENV === 'test';
|
|
386
|
+
const explicitlyDisabled = process.env.BRAINY_FORCE_BUFFERING === 'false';
|
|
387
|
+
// Use reasonable thresholds instead of emergency aggressive ones
|
|
388
|
+
const reasonableThreshold = Math.max(threshold, 10); // At least 10 pending operations
|
|
389
|
+
const highSocketUtilization = 0.8; // 80% socket utilization
|
|
390
|
+
const highRequestRate = 50; // 50 requests per second
|
|
391
|
+
const significantErrors = 5; // 5 consecutive errors
|
|
392
|
+
const shouldEnableHighVolume = !isTestEnvironment && // Disable in test environment
|
|
393
|
+
!explicitlyDisabled && // Allow explicit disabling
|
|
394
|
+
(this.forceHighVolumeMode || // Environment override
|
|
395
|
+
backpressureStatus.queueLength >= reasonableThreshold || // High queue backlog
|
|
396
|
+
socketMetrics.pendingRequests >= reasonableThreshold || // Many pending requests
|
|
397
|
+
this.pendingOperations >= reasonableThreshold || // Many pending ops
|
|
398
|
+
socketMetrics.socketUtilization >= highSocketUtilization || // High socket pressure
|
|
399
|
+
(socketMetrics.requestsPerSecond >= highRequestRate) || // High request rate
|
|
400
|
+
(this.consecutiveErrors >= significantErrors)); // Significant error pattern
|
|
393
401
|
if (shouldEnableHighVolume && !this.highVolumeMode) {
|
|
394
402
|
this.highVolumeMode = true;
|
|
395
403
|
this.logger.warn(`🚨 HIGH-VOLUME MODE ACTIVATED 🚨`);
|
|
@@ -1278,8 +1286,42 @@ export class S3CompatibleStorage extends BaseStorage {
|
|
|
1278
1286
|
graphVerbs.push(graphVerb);
|
|
1279
1287
|
}
|
|
1280
1288
|
}
|
|
1289
|
+
// Apply filtering at GraphVerb level since HNSWVerb filtering is not supported
|
|
1290
|
+
let filteredGraphVerbs = graphVerbs;
|
|
1291
|
+
if (options.filter) {
|
|
1292
|
+
filteredGraphVerbs = graphVerbs.filter((graphVerb) => {
|
|
1293
|
+
// Filter by sourceId
|
|
1294
|
+
if (options.filter.sourceId) {
|
|
1295
|
+
const sourceIds = Array.isArray(options.filter.sourceId)
|
|
1296
|
+
? options.filter.sourceId
|
|
1297
|
+
: [options.filter.sourceId];
|
|
1298
|
+
if (!sourceIds.includes(graphVerb.sourceId)) {
|
|
1299
|
+
return false;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
// Filter by targetId
|
|
1303
|
+
if (options.filter.targetId) {
|
|
1304
|
+
const targetIds = Array.isArray(options.filter.targetId)
|
|
1305
|
+
? options.filter.targetId
|
|
1306
|
+
: [options.filter.targetId];
|
|
1307
|
+
if (!targetIds.includes(graphVerb.targetId)) {
|
|
1308
|
+
return false;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
// Filter by verbType (maps to type field)
|
|
1312
|
+
if (options.filter.verbType) {
|
|
1313
|
+
const verbTypes = Array.isArray(options.filter.verbType)
|
|
1314
|
+
? options.filter.verbType
|
|
1315
|
+
: [options.filter.verbType];
|
|
1316
|
+
if (graphVerb.type && !verbTypes.includes(graphVerb.type)) {
|
|
1317
|
+
return false;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
return true;
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1281
1323
|
return {
|
|
1282
|
-
items:
|
|
1324
|
+
items: filteredGraphVerbs,
|
|
1283
1325
|
hasMore: result.hasMore,
|
|
1284
1326
|
nextCursor: result.nextCursor
|
|
1285
1327
|
};
|
|
@@ -1288,46 +1330,34 @@ export class S3CompatibleStorage extends BaseStorage {
|
|
|
1288
1330
|
* Get verbs by source (internal implementation)
|
|
1289
1331
|
*/
|
|
1290
1332
|
async getVerbsBySource_internal(sourceId) {
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
// This method is deprecated and would require loading metadata for each edge
|
|
1298
|
-
// For now, return empty array since this is not efficiently implementable with new storage pattern
|
|
1299
|
-
this.logger.trace('getEdgesBySource is deprecated and not efficiently supported in new storage pattern');
|
|
1300
|
-
return [];
|
|
1333
|
+
// Use the paginated approach to properly handle HNSWVerb to GraphVerb conversion
|
|
1334
|
+
const result = await this.getVerbsWithPagination({
|
|
1335
|
+
filter: { sourceId: [sourceId] },
|
|
1336
|
+
limit: Number.MAX_SAFE_INTEGER // Get all matching results
|
|
1337
|
+
});
|
|
1338
|
+
return result.items;
|
|
1301
1339
|
}
|
|
1302
1340
|
/**
|
|
1303
1341
|
* Get verbs by target (internal implementation)
|
|
1304
1342
|
*/
|
|
1305
1343
|
async getVerbsByTarget_internal(targetId) {
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
// This method is deprecated and would require loading metadata for each edge
|
|
1313
|
-
// For now, return empty array since this is not efficiently implementable with new storage pattern
|
|
1314
|
-
this.logger.trace('getEdgesByTarget is deprecated and not efficiently supported in new storage pattern');
|
|
1315
|
-
return [];
|
|
1344
|
+
// Use the paginated approach to properly handle HNSWVerb to GraphVerb conversion
|
|
1345
|
+
const result = await this.getVerbsWithPagination({
|
|
1346
|
+
filter: { targetId: [targetId] },
|
|
1347
|
+
limit: Number.MAX_SAFE_INTEGER // Get all matching results
|
|
1348
|
+
});
|
|
1349
|
+
return result.items;
|
|
1316
1350
|
}
|
|
1317
1351
|
/**
|
|
1318
1352
|
* Get verbs by type (internal implementation)
|
|
1319
1353
|
*/
|
|
1320
1354
|
async getVerbsByType_internal(type) {
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
// This method is deprecated and would require loading metadata for each edge
|
|
1328
|
-
// For now, return empty array since this is not efficiently implementable with new storage pattern
|
|
1329
|
-
this.logger.trace('getEdgesByType is deprecated and not efficiently supported in new storage pattern');
|
|
1330
|
-
return [];
|
|
1355
|
+
// Use the paginated approach to properly handle HNSWVerb to GraphVerb conversion
|
|
1356
|
+
const result = await this.getVerbsWithPagination({
|
|
1357
|
+
filter: { verbType: [type] },
|
|
1358
|
+
limit: Number.MAX_SAFE_INTEGER // Get all matching results
|
|
1359
|
+
});
|
|
1360
|
+
return result.items;
|
|
1331
1361
|
}
|
|
1332
1362
|
/**
|
|
1333
1363
|
* Delete a verb from storage (internal implementation)
|
|
@@ -72,11 +72,10 @@ export declare abstract class BaseStorage extends BaseStorageAdapter {
|
|
|
72
72
|
*/
|
|
73
73
|
protected convertHNSWVerbToGraphVerb(hnswVerb: HNSWVerb): Promise<GraphVerb | null>;
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
76
|
-
* @
|
|
77
|
-
* @deprecated This method loads all data into memory and may cause performance issues. Use getVerbs() with pagination instead.
|
|
75
|
+
* Internal method for loading all verbs - used by performance optimizations
|
|
76
|
+
* @internal - Do not use directly, use getVerbs() with pagination instead
|
|
78
77
|
*/
|
|
79
|
-
|
|
78
|
+
protected _loadAllVerbsForOptimization(): Promise<HNSWVerb[]>;
|
|
80
79
|
/**
|
|
81
80
|
* Get verbs by source
|
|
82
81
|
*/
|
|
@@ -90,11 +89,10 @@ export declare abstract class BaseStorage extends BaseStorageAdapter {
|
|
|
90
89
|
*/
|
|
91
90
|
getVerbsByType(type: string): Promise<GraphVerb[]>;
|
|
92
91
|
/**
|
|
93
|
-
*
|
|
94
|
-
* @
|
|
95
|
-
* @deprecated This method loads all data into memory and may cause performance issues. Use getNouns() with pagination instead.
|
|
92
|
+
* Internal method for loading all nouns - used by performance optimizations
|
|
93
|
+
* @internal - Do not use directly, use getNouns() with pagination instead
|
|
96
94
|
*/
|
|
97
|
-
|
|
95
|
+
protected _loadAllNounsForOptimization(): Promise<HNSWNoun[]>;
|
|
98
96
|
/**
|
|
99
97
|
* Get nouns with pagination and filtering
|
|
100
98
|
* @param options Pagination and filtering options
|
|
@@ -181,27 +181,22 @@ export class BaseStorage extends BaseStorageAdapter {
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
/**
|
|
184
|
-
*
|
|
185
|
-
* @
|
|
186
|
-
* @deprecated This method loads all data into memory and may cause performance issues. Use getVerbs() with pagination instead.
|
|
184
|
+
* Internal method for loading all verbs - used by performance optimizations
|
|
185
|
+
* @internal - Do not use directly, use getVerbs() with pagination instead
|
|
187
186
|
*/
|
|
188
|
-
async
|
|
187
|
+
async _loadAllVerbsForOptimization() {
|
|
189
188
|
await this.ensureInitialized();
|
|
190
|
-
|
|
191
|
-
// Get all verbs using the paginated method with a very large limit
|
|
189
|
+
// Only use this for internal optimizations when safe
|
|
192
190
|
const result = await this.getVerbs({
|
|
193
|
-
pagination: {
|
|
194
|
-
limit: Number.MAX_SAFE_INTEGER
|
|
195
|
-
}
|
|
191
|
+
pagination: { limit: Number.MAX_SAFE_INTEGER }
|
|
196
192
|
});
|
|
197
|
-
// Convert GraphVerbs back to HNSWVerbs
|
|
193
|
+
// Convert GraphVerbs back to HNSWVerbs for internal use
|
|
198
194
|
const hnswVerbs = [];
|
|
199
195
|
for (const graphVerb of result.items) {
|
|
200
|
-
// Create an HNSWVerb from the GraphVerb (reverse conversion)
|
|
201
196
|
const hnswVerb = {
|
|
202
197
|
id: graphVerb.id,
|
|
203
198
|
vector: graphVerb.vector,
|
|
204
|
-
connections: new Map()
|
|
199
|
+
connections: new Map()
|
|
205
200
|
};
|
|
206
201
|
hnswVerbs.push(hnswVerb);
|
|
207
202
|
}
|
|
@@ -241,17 +236,14 @@ export class BaseStorage extends BaseStorageAdapter {
|
|
|
241
236
|
return result.items;
|
|
242
237
|
}
|
|
243
238
|
/**
|
|
244
|
-
*
|
|
245
|
-
* @
|
|
246
|
-
* @deprecated This method loads all data into memory and may cause performance issues. Use getNouns() with pagination instead.
|
|
239
|
+
* Internal method for loading all nouns - used by performance optimizations
|
|
240
|
+
* @internal - Do not use directly, use getNouns() with pagination instead
|
|
247
241
|
*/
|
|
248
|
-
async
|
|
242
|
+
async _loadAllNounsForOptimization() {
|
|
249
243
|
await this.ensureInitialized();
|
|
250
|
-
|
|
244
|
+
// Only use this for internal optimizations when safe
|
|
251
245
|
const result = await this.getNouns({
|
|
252
|
-
pagination: {
|
|
253
|
-
limit: Number.MAX_SAFE_INTEGER
|
|
254
|
-
}
|
|
246
|
+
pagination: { limit: Number.MAX_SAFE_INTEGER }
|
|
255
247
|
});
|
|
256
248
|
return result.items;
|
|
257
249
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soulcraft/brainy",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.61.1",
|
|
4
|
+
"description": "Multi-Dimensional AI Database - Vector similarity, graph relationships, metadata facets with HNSW indexing and OPFS storage",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -158,13 +158,13 @@
|
|
|
158
158
|
"publishConfig": {
|
|
159
159
|
"access": "public"
|
|
160
160
|
},
|
|
161
|
-
"homepage": "https://github.com/
|
|
161
|
+
"homepage": "https://github.com/soulcraftlabs/brainy",
|
|
162
162
|
"bugs": {
|
|
163
|
-
"url": "https://github.com/
|
|
163
|
+
"url": "https://github.com/soulcraftlabs/brainy/issues"
|
|
164
164
|
},
|
|
165
165
|
"repository": {
|
|
166
166
|
"type": "git",
|
|
167
|
-
"url": "git+https://github.com/
|
|
167
|
+
"url": "git+https://github.com/soulcraftlabs/brainy.git"
|
|
168
168
|
},
|
|
169
169
|
"files": [
|
|
170
170
|
"dist/**/*.js",
|