fix: combine vector and metadata in getNoun/getVerb internal methods

Fixed critical bug in 2-file architecture where getNoun_internal() and
getVerb_internal() only returned vector data without metadata, causing
brain.get() to return null despite data being correctly saved.

Changes:
- Updated all 5 storage adapters (GCS, S3, FileSystem, Memory, OPFS)
- Fixed getNoun_internal() to fetch and combine vector + metadata
- Fixed getVerb_internal() to fetch and combine vector + metadata
- Added metadata field to HNSWVerb interface for consistency

The 2-file architecture now works correctly for both read and write operations.
This commit is contained in:
David Snelling 2025-10-10 16:51:59 -07:00
parent 30063d440a
commit cb1e37c0e8
6 changed files with 140 additions and 30 deletions

View file

@ -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<HNSWVerb | null> {
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 || {}
}
}
/**