@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.
@@ -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
- // EXTREMELY aggressive detection - activate on ANY load
385
- const shouldEnableHighVolume = this.forceHighVolumeMode || // Environment override
386
- backpressureStatus.queueLength >= threshold || // Configurable threshold (>= 0 by default!)
387
- socketMetrics.pendingRequests >= threshold || // Socket pressure
388
- this.pendingOperations >= threshold || // Any pending ops
389
- socketMetrics.socketUtilization >= 0.01 || // Even 1% socket usage
390
- (socketMetrics.requestsPerSecond >= 1) || // Any request rate
391
- (this.consecutiveErrors >= 0) || // Always true - any system activity
392
- true; // FORCE ENABLE for emergency debugging
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: graphVerbs,
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
- return this.getEdgesBySource(sourceId);
1292
- }
1293
- /**
1294
- * Get edges by source
1295
- */
1296
- async getEdgesBySource(sourceId) {
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
- return this.getEdgesByTarget(targetId);
1307
- }
1308
- /**
1309
- * Get edges by target
1310
- */
1311
- async getEdgesByTarget(targetId) {
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
- return this.getEdgesByType(type);
1322
- }
1323
- /**
1324
- * Get edges by type
1325
- */
1326
- async getEdgesByType(type) {
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
- * Get all verbs from storage
76
- * @returns Promise that resolves to an array of all HNSWVerbs
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
- getAllVerbs(): Promise<HNSWVerb[]>;
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
- * Get all nouns from storage
94
- * @returns Promise that resolves to an array of all nouns
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
- getAllNouns(): Promise<HNSWNoun[]>;
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
- * Get all verbs from storage
185
- * @returns Promise that resolves to an array of all HNSWVerbs
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 getAllVerbs() {
187
+ async _loadAllVerbsForOptimization() {
189
188
  await this.ensureInitialized();
190
- console.warn('getAllVerbs() is deprecated and may cause memory issues with large datasets. Consider using getVerbs() with pagination instead.');
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 since that's what this method should return
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() // HNSWVerbs need connections, but GraphVerbs don't have them
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
- * Get all nouns from storage
245
- * @returns Promise that resolves to an array of all nouns
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 getAllNouns() {
242
+ async _loadAllNounsForOptimization() {
249
243
  await this.ensureInitialized();
250
- console.warn('getAllNouns() is deprecated and may cause memory issues with large datasets. Consider using getNouns() with pagination instead.');
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.60.0",
4
- "description": "A vector graph database using HNSW indexing with Origin Private File System storage",
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/soulcraft-research/brainy",
161
+ "homepage": "https://github.com/soulcraftlabs/brainy",
162
162
  "bugs": {
163
- "url": "https://github.com/soulcraft-research/brainy/issues"
163
+ "url": "https://github.com/soulcraftlabs/brainy/issues"
164
164
  },
165
165
  "repository": {
166
166
  "type": "git",
167
- "url": "git+https://github.com/soulcraft-research/brainy.git"
167
+ "url": "git+https://github.com/soulcraftlabs/brainy.git"
168
168
  },
169
169
  "files": [
170
170
  "dist/**/*.js",