@soulcraft/brainy 0.17.0 → 0.18.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.
@@ -357,6 +357,16 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
357
357
  * Get the number of vectors in the database
358
358
  */
359
359
  size(): number;
360
+ /**
361
+ * Get statistics about the current state of the database
362
+ * @returns Object containing counts of nouns, verbs, metadata entries, and HNSW index size
363
+ */
364
+ getStatistics(): Promise<{
365
+ nounCount: number;
366
+ verbCount: number;
367
+ metadataCount: number;
368
+ hnswIndexSize: number;
369
+ }>;
360
370
  /**
361
371
  * Check if the database is in read-only mode
362
372
  * @returns True if the database is in read-only mode, false otherwise
package/dist/unified.js CHANGED
@@ -10451,6 +10451,47 @@ class BrainyData {
10451
10451
  size() {
10452
10452
  return this.index.size();
10453
10453
  }
10454
+ /**
10455
+ * Get statistics about the current state of the database
10456
+ * @returns Object containing counts of nouns, verbs, metadata entries, and HNSW index size
10457
+ */
10458
+ async getStatistics() {
10459
+ await this.ensureInitialized();
10460
+ try {
10461
+ // Get noun count from the index
10462
+ const nounCount = this.index.getNouns().size;
10463
+ // Get verb count from storage
10464
+ const allVerbs = await this.storage.getAllVerbs();
10465
+ const verbCount = allVerbs.length;
10466
+ // Count metadata entries by checking each noun for metadata
10467
+ let metadataCount = 0;
10468
+ const nouns = this.index.getNouns();
10469
+ for (const [id] of nouns.entries()) {
10470
+ try {
10471
+ const metadata = await this.storage.getMetadata(id);
10472
+ if (metadata !== null && metadata !== undefined) {
10473
+ metadataCount++;
10474
+ }
10475
+ }
10476
+ catch (error) {
10477
+ // Ignore errors when checking individual metadata entries
10478
+ // This could happen if metadata is corrupted or missing
10479
+ }
10480
+ }
10481
+ // Get HNSW index size
10482
+ const hnswIndexSize = this.index.size();
10483
+ return {
10484
+ nounCount,
10485
+ verbCount,
10486
+ metadataCount,
10487
+ hnswIndexSize
10488
+ };
10489
+ }
10490
+ catch (error) {
10491
+ console.error('Failed to get statistics:', error);
10492
+ throw new Error(`Failed to get statistics: ${error}`);
10493
+ }
10494
+ }
10454
10495
  /**
10455
10496
  * Check if the database is in read-only mode
10456
10497
  * @returns True if the database is in read-only mode, false otherwise