diff --git a/src/coreTypes.ts b/src/coreTypes.ts index edd59177..ee7160a8 100644 --- a/src/coreTypes.ts +++ b/src/coreTypes.ts @@ -94,6 +94,7 @@ export interface HNSWVerb { id: string vector: Vector connections: Map> // level -> set of connected verb ids + metadata?: any // Optional metadata for the verb (2-file system) } /** diff --git a/src/storage/adapters/fileSystemStorage.ts b/src/storage/adapters/fileSystemStorage.ts index 5f2232c1..6529447b 100644 --- a/src/storage/adapters/fileSystemStorage.ts +++ b/src/storage/adapters/fileSystemStorage.ts @@ -1043,10 +1043,24 @@ export class FileSystemStorage extends BaseStorage { } /** - * Get a noun from storage + * Get a noun from storage (internal implementation) + * Combines vector data from getNode() with metadata from getNounMetadata() */ protected async getNoun_internal(id: string): Promise { - return this.getNode(id) + // Get vector data (lightweight) + const node = await this.getNode(id) + if (!node) { + return null + } + + // Get metadata (entity data in 2-file system) + const metadata = await this.getNounMetadata(id) + + // Combine into complete noun object + return { + ...node, + metadata: metadata || {} + } } @@ -1074,10 +1088,24 @@ export class FileSystemStorage extends BaseStorage { } /** - * Get a verb from storage + * Get a verb from storage (internal implementation) + * Combines vector data from getEdge() with metadata from getVerbMetadata() */ protected async getVerb_internal(id: string): Promise { - return this.getEdge(id) + // Get vector data (lightweight) + const edge = await this.getEdge(id) + if (!edge) { + return null + } + + // Get metadata (relationship data in 2-file system) + const metadata = await this.getVerbMetadata(id) + + // Combine into complete verb object + return { + ...edge, + metadata: metadata || {} + } } diff --git a/src/storage/adapters/gcsStorage.ts b/src/storage/adapters/gcsStorage.ts index 8d21312f..8a107e7c 100644 --- a/src/storage/adapters/gcsStorage.ts +++ b/src/storage/adapters/gcsStorage.ts @@ -482,9 +482,23 @@ export class GcsStorage extends BaseStorage { /** * Get a noun from storage (internal implementation) + * Combines vector data from getNode() with metadata from getNounMetadata() */ protected async getNoun_internal(id: string): Promise { - return this.getNode(id) + // Get vector data (lightweight) + const node = await this.getNode(id) + if (!node) { + return null + } + + // Get metadata (entity data in 2-file system) + const metadata = await this.getNounMetadata(id) + + // Combine into complete noun object + return { + ...node, + metadata: metadata || {} + } } /** @@ -798,9 +812,23 @@ export class GcsStorage extends BaseStorage { /** * Get a verb from storage (internal implementation) + * Combines vector data from getEdge() with metadata from getVerbMetadata() */ protected async getVerb_internal(id: string): Promise { - return this.getEdge(id) + // Get vector data (lightweight) + const edge = await this.getEdge(id) + if (!edge) { + return null + } + + // Get metadata (relationship data in 2-file system) + const metadata = await this.getVerbMetadata(id) + + // Combine into complete verb object + return { + ...edge, + metadata: metadata || {} + } } /** diff --git a/src/storage/adapters/memoryStorage.ts b/src/storage/adapters/memoryStorage.ts index 74a4af6f..7d2edadf 100644 --- a/src/storage/adapters/memoryStorage.ts +++ b/src/storage/adapters/memoryStorage.ts @@ -78,7 +78,8 @@ export class MemoryStorage extends BaseStorage { } /** - * Get a noun from storage + * Get a noun from storage (internal implementation) + * Combines vector data from nouns map with metadata from getNounMetadata() */ protected async getNoun_internal(id: string): Promise { // Get the noun directly from the nouns map @@ -90,14 +91,11 @@ export class MemoryStorage extends BaseStorage { } // Return a deep copy to avoid reference issues - // CRITICAL: Only return lightweight vector data (no metadata) - // Metadata is retrieved separately via getNounMetadata() (2-file system) const nounCopy: HNSWNoun = { id: noun.id, vector: [...noun.vector], connections: new Map(), level: noun.level || 0 - // NO metadata field - retrieved separately for scalability } // Copy connections @@ -105,7 +103,14 @@ export class MemoryStorage extends BaseStorage { nounCopy.connections.set(level, new Set(connections)) } - return nounCopy + // Get metadata (entity data in 2-file system) + const metadata = await this.getNounMetadata(id) + + // Combine into complete noun object + return { + ...nounCopy, + metadata: metadata || {} + } } /** @@ -303,7 +308,8 @@ export class MemoryStorage extends BaseStorage { } /** - * Get a verb from storage + * Get a verb from storage (internal implementation) + * Combines vector data from verbs map with metadata from getVerbMetadata() */ protected async getVerb_internal(id: string): Promise { // Get the verb directly from the verbs map @@ -314,18 +320,6 @@ export class MemoryStorage extends BaseStorage { return null } - // Create default timestamp if not present - const defaultTimestamp = { - seconds: Math.floor(Date.now() / 1000), - nanoseconds: (Date.now() % 1000) * 1000000 - } - - // Create default createdBy if not present - const defaultCreatedBy = { - augmentation: 'unknown', - version: '1.0' - } - // Return a deep copy of the HNSWVerb const verbCopy: HNSWVerb = { id: verb.id, @@ -338,7 +332,14 @@ export class MemoryStorage extends BaseStorage { verbCopy.connections.set(level, new Set(connections)) } - return verbCopy + // Get metadata (relationship data in 2-file system) + const metadata = await this.getVerbMetadata(id) + + // Combine into complete verb object + return { + ...verbCopy, + metadata: metadata || {} + } } /** diff --git a/src/storage/adapters/opfsStorage.ts b/src/storage/adapters/opfsStorage.ts index 149993a5..9d982413 100644 --- a/src/storage/adapters/opfsStorage.ts +++ b/src/storage/adapters/opfsStorage.ts @@ -237,7 +237,8 @@ export class OPFSStorage extends BaseStorage { } /** - * Get a noun from storage + * Get a noun from storage (internal implementation) + * Combines vector data from file with metadata from getNounMetadata() */ protected async getNoun_internal( id: string @@ -265,12 +266,21 @@ export class OPFSStorage extends BaseStorage { connections.set(Number(level), new Set(nounIds as string[])) } - return { + const node = { id: data.id, vector: data.vector, connections, level: data.level || 0 } + + // Get metadata (entity data in 2-file system) + const metadata = await this.getNounMetadata(id) + + // Combine into complete noun object + return { + ...node, + metadata: metadata || {} + } } catch (error) { // Noun not found or other error return null @@ -427,9 +437,23 @@ export class OPFSStorage extends BaseStorage { /** * Get a verb from storage (internal implementation) + * Combines vector data from getEdge() with metadata from getVerbMetadata() */ protected async getVerb_internal(id: string): Promise { - return this.getEdge(id) + // Get vector data (lightweight) + const edge = await this.getEdge(id) + if (!edge) { + return null + } + + // Get metadata (relationship data in 2-file system) + const metadata = await this.getVerbMetadata(id) + + // Combine into complete verb object + return { + ...edge, + metadata: metadata || {} + } } /** diff --git a/src/storage/adapters/s3CompatibleStorage.ts b/src/storage/adapters/s3CompatibleStorage.ts index 0c8b3cae..eaaf629f 100644 --- a/src/storage/adapters/s3CompatibleStorage.ts +++ b/src/storage/adapters/s3CompatibleStorage.ts @@ -1048,9 +1048,23 @@ export class S3CompatibleStorage extends BaseStorage { /** * Get a noun from storage (internal implementation) + * Combines vector data from getNode() with metadata from getNounMetadata() */ protected async getNoun_internal(id: string): Promise { - return this.getNode(id) + // Get vector data (lightweight) + const node = await this.getNode(id) + if (!node) { + return null + } + + // Get metadata (entity data in 2-file system) + const metadata = await this.getNounMetadata(id) + + // Combine into complete noun object + return { + ...node, + metadata: metadata || {} + } } /** @@ -1507,9 +1521,23 @@ export class S3CompatibleStorage extends BaseStorage { /** * Get a verb from storage (internal implementation) + * Combines vector data from getEdge() with metadata from getVerbMetadata() */ protected async getVerb_internal(id: string): Promise { - return this.getEdge(id) + // Get vector data (lightweight) + const edge = await this.getEdge(id) + if (!edge) { + return null + } + + // Get metadata (relationship data in 2-file system) + const metadata = await this.getVerbMetadata(id) + + // Combine into complete verb object + return { + ...edge, + metadata: metadata || {} + } } /**