**feat(core, storage, tests): enhance verb construction with timestamps and metadata**

- **Core**: Improved verb creation logic by adding `createdAt`, `updatedAt`, and `createdBy` attributes. These fields include timestamped metadata (`seconds`, `nanoseconds`) and source augmentation/service information for better tracking.
- **Storage**: Refactored `BaseStorage` methods to utilize internal variants (e.g., `saveVerb_internal`, `getNoun_internal`). Added support for new verb attributes while maintaining backward compatibility with existing data structures.
- **Tests**:
  - Updated `s3-storage.test.ts` and `opfs-storage.test.ts` to validate changes in verb attributes such as timestamps and augmentation metadata.
  - Added assertions for `createdAt`, `updatedAt`, and `createdBy` fields in test cases.
- **Cleanup**: Replaced ambiguous type aliases like `Edge` and `HNSWNode` with clearer equivalents (`Verb` and `HNSWNoun_internal`) for consistency across storage adapters.

**Purpose**: Enhance metadata tracking and standardize attribute handling across storage and core modules to ensure accurate and consistent data throughout the system.
This commit is contained in:
David Snelling 2025-07-25 09:44:10 -07:00
parent ae3560aad3
commit 501244398e
10 changed files with 641 additions and 310 deletions

View file

@ -1656,16 +1656,34 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
}
}
// Get service name from options or current augmentation
const service = options.service || this.getCurrentAugmentation()
// Create timestamp for creation/update time
const now = new Date()
const timestamp = {
seconds: Math.floor(now.getTime() / 1000),
nanoseconds: (now.getTime() % 1000) * 1000000
}
// Create verb
const verb: GraphVerb = {
id,
vector: verbVector,
connections: new Map(),
sourceId,
targetId,
type: verbType,
sourceId: sourceId,
targetId: targetId,
source: sourceId,
target: targetId,
verb: verbType as VerbType,
weight: options.weight,
metadata: options.metadata
metadata: options.metadata,
createdAt: timestamp,
updatedAt: timestamp,
createdBy: {
augmentation: service,
version: '1.0' // TODO: Get actual version from augmentation
}
}
// Add to index
@ -1687,8 +1705,8 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
await this.storage!.saveVerb(verb)
// Track verb statistics
const service = options.service || 'default'
await this.storage!.incrementStatistic('verb', service)
const serviceForStats = options.service || 'default'
await this.storage!.incrementStatistic('verb', serviceForStats)
// Update HNSW index size (excluding verbs)
await this.storage!.updateHnswIndexSize(await this.getNounCount())