feat: brain.get() metadata-only optimization - Phase 2 (testing)
Fixed convertMetadataToEntity() to properly extract custom metadata fields
using same destructuring pattern as baseStorage.getNoun(). This ensures
metadata is correctly populated in metadata-only entities.
Test Updates:
- Fixed unit tests to add { includeVectors: true } where vectors are checked
- Created comprehensive brain.get() optimization tests (11 tests, all passing)
- Created VFS performance integration tests
- Fixed invalid NounType references (NounType.Place → NounType.Location)
- Adjusted performance expectations for MemoryStorage (10%+ vs 75%+ for FS)
Files Updated:
- src/brainy.ts: Fixed convertMetadataToEntity() destructuring
- tests/unit/brainy-get-optimization.test.ts: New comprehensive tests
- tests/unit/brainy/get.test.ts: Added includeVectors where needed
- tests/unit/brainy/batch-operations.test.ts: Added includeVectors
- tests/unit/brainy/update.test.ts: Added includeVectors
- tests/unit/brainy/add.test.ts: Added includeVectors (3 tests)
- tests/brainy-3.test.ts: Added includeVectors
This commit is contained in:
parent
8dcf299fe7
commit
f2f6a6c939
7 changed files with 276 additions and 28 deletions
|
|
@ -764,22 +764,26 @@ export class Brainy<T = any> implements BrainyInterface<T> {
|
|||
// v5.11.1: Metadata-only entity (no vector loading)
|
||||
// This is 76-81% faster for operations that don't need semantic similarity
|
||||
|
||||
// v4.8.0: Extract standard fields, rest are custom metadata
|
||||
// Same destructuring as baseStorage.getNoun() to ensure consistency
|
||||
const { noun, createdAt, updatedAt, confidence, weight, service, data, createdBy, ...customMetadata } = metadata
|
||||
|
||||
const entity: Entity<T> = {
|
||||
id,
|
||||
vector: [], // Stub vector (empty array - vectors not loaded for metadata-only)
|
||||
type: metadata.noun as NounType || NounType.Thing,
|
||||
type: noun as NounType || NounType.Thing,
|
||||
|
||||
// Standard fields from metadata
|
||||
confidence: metadata.confidence,
|
||||
weight: metadata.weight,
|
||||
createdAt: metadata.createdAt || Date.now(),
|
||||
updatedAt: metadata.updatedAt || Date.now(),
|
||||
service: metadata.service,
|
||||
data: metadata.data,
|
||||
createdBy: metadata.createdBy,
|
||||
confidence,
|
||||
weight,
|
||||
createdAt: createdAt || Date.now(),
|
||||
updatedAt: updatedAt || Date.now(),
|
||||
service,
|
||||
data,
|
||||
createdBy,
|
||||
|
||||
// Custom user fields (v4.8.0: separated by storage)
|
||||
metadata: metadata.metadata as T
|
||||
// Custom user fields (v4.8.0: standard fields removed, only custom remain)
|
||||
metadata: customMetadata as T
|
||||
}
|
||||
|
||||
return entity
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue