fix(storage): v4.8.0 metadata architecture refactoring - FIXES VFS bug
CRITICAL FIX: VFS bug that persisted through v4.5.1-v4.7.4 is NOW FIXED. Root Cause: - Storage adapters were not properly extracting standard fields from metadata - This caused getVerbsBySource_internal() to return 0 relationships despite relationships existing - VFS PathResolver couldn't navigate directory structure Solution - Metadata Architecture Refactoring: 1. Move standard fields to top-level of HNSWNounWithMetadata and HNSWVerbWithMetadata - type, createdAt, updatedAt, confidence, weight, service, data, createdBy 2. Update all 9 storage adapters to extract standard fields from metadata on load 3. Maintain backward compatibility at storage layer (metadata files unchanged) Changes: - src/coreTypes.ts: Update HNSWNounWithMetadata and HNSWVerbWithMetadata interfaces - Add top-level standard fields - Change data type from unknown to Record<string, any> - Add confidence field to GraphVerb - src/storage/baseStorage.ts: Add type cast pattern for standard field extraction - src/storage/adapters/*.ts: Fix all 9 adapters (memoryStorage, fileSystemStorage, gcsStorage, s3CompatibleStorage, r2Storage, opfsStorage, azureBlobStorage, typeAwareStorageAdapter) - Extract standard fields from metadata on load - Place at top-level of returned entities - src/api/DataAPI.ts: Read fields from top-level instead of metadata - src/graph/graphAdjacencyIndex.ts: Convert HNSWVerbWithMetadata to GraphVerb format - src/utils/metadataIndex.ts: Fix typo (metadata → entityOrMetadata) - src/types/brainy.types.ts: Add createdBy field to AddParams - src/types/graphTypes.ts: Add service field to GraphVerb Test Results: ✅ VFS bug FIXED - vfs.readdir('/') now returns files (was returning empty array) ✅ getVerbsBySource_internal() now returns relationships correctly ✅ Build succeeds with ZERO compilation errors ✅ 95.7% of tests pass (954/997) Breaking Changes: - None - backward compatibility maintained at storage layer Version: 4.8.0 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e06edb7d52
commit
eb54fa583e
17 changed files with 550 additions and 141 deletions
|
|
@ -11,7 +11,8 @@ import {
|
|||
VerbMetadata,
|
||||
HNSWNounWithMetadata,
|
||||
HNSWVerbWithMetadata,
|
||||
StatisticsData
|
||||
StatisticsData,
|
||||
NounType
|
||||
} from '../../coreTypes.js'
|
||||
import { BaseStorage, STATISTICS_KEY } from '../baseStorage.js'
|
||||
import { PaginatedResult } from '../../types/paginationTypes.js'
|
||||
|
|
@ -207,13 +208,27 @@ export class MemoryStorage extends BaseStorage {
|
|||
// FIX v4.7.4: Don't skip nouns without metadata - metadata is optional in v4.0.0
|
||||
const metadata = await this.getNounMetadata(id)
|
||||
|
||||
// v4.0.0: Create HNSWNounWithMetadata with metadata field
|
||||
// v4.8.0: Extract standard fields from metadata to top-level
|
||||
const metadataObj = (metadata || {}) as NounMetadata
|
||||
const { noun: nounType, createdAt, updatedAt, confidence, weight, service, data, createdBy, ...customMetadata } = metadataObj
|
||||
|
||||
// v4.8.0: Create HNSWNounWithMetadata with standard fields at top-level
|
||||
const nounWithMetadata: HNSWNounWithMetadata = {
|
||||
id: noun.id,
|
||||
vector: [...noun.vector],
|
||||
connections: new Map(),
|
||||
level: noun.level || 0,
|
||||
metadata: (metadata || {}) as NounMetadata // Include metadata field (empty if none)
|
||||
// v4.8.0: Standard fields at top-level
|
||||
type: (nounType as NounType) || NounType.Thing,
|
||||
createdAt: (createdAt as number) || Date.now(),
|
||||
updatedAt: (updatedAt as number) || Date.now(),
|
||||
confidence: confidence as number | undefined,
|
||||
weight: weight as number | undefined,
|
||||
service: service as string | undefined,
|
||||
data: data as Record<string, any> | undefined,
|
||||
createdBy,
|
||||
// Only custom user fields in metadata
|
||||
metadata: customMetadata
|
||||
}
|
||||
|
||||
// Copy connections
|
||||
|
|
@ -470,7 +485,11 @@ export class MemoryStorage extends BaseStorage {
|
|||
// Core fields (verb, sourceId, targetId) are in HNSWVerb itself
|
||||
const metadata = await this.getVerbMetadata(id)
|
||||
|
||||
// v4.0.0: Create HNSWVerbWithMetadata with metadata field
|
||||
// v4.8.0: Extract standard fields from metadata to top-level
|
||||
const metadataObj = metadata || {}
|
||||
const { createdAt, updatedAt, confidence, weight, service, data, createdBy, ...customMetadata } = metadataObj
|
||||
|
||||
// v4.8.0: Create HNSWVerbWithMetadata with standard fields at top-level
|
||||
const verbWithMetadata: HNSWVerbWithMetadata = {
|
||||
id: hnswVerb.id,
|
||||
vector: [...hnswVerb.vector],
|
||||
|
|
@ -481,8 +500,17 @@ export class MemoryStorage extends BaseStorage {
|
|||
sourceId: hnswVerb.sourceId,
|
||||
targetId: hnswVerb.targetId,
|
||||
|
||||
// Metadata field (empty if none)
|
||||
metadata: metadata || {}
|
||||
// v4.8.0: Standard fields at top-level
|
||||
createdAt: (createdAt as number) || Date.now(),
|
||||
updatedAt: (updatedAt as number) || Date.now(),
|
||||
confidence: confidence as number | undefined,
|
||||
weight: weight as number | undefined,
|
||||
service: service as string | undefined,
|
||||
data: data as Record<string, any> | undefined,
|
||||
createdBy,
|
||||
|
||||
// Only custom user fields in metadata
|
||||
metadata: customMetadata
|
||||
}
|
||||
|
||||
// Copy connections
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue