fix(core): resolve TypeScript compilation errors and test failures
- Add missing 'level' property to HNSWNoun objects in storage adapters - Fix HNSWVerb type compatibility in CacheManager imports - Clear statistics cache when clearing storage to prevent stale data - Update test expectations to match actual HNSW index behavior (includes both nouns and verbs) - Add StatisticsCollector utility for enhanced metrics tracking - Improve statistics comparison in tests to handle volatile fields
This commit is contained in:
parent
8c1c9a08d3
commit
ba890170bf
12 changed files with 668 additions and 112 deletions
|
|
@ -193,7 +193,8 @@ export class FileSystemStorage extends BaseStorage {
|
|||
return {
|
||||
id: parsedNode.id,
|
||||
vector: parsedNode.vector,
|
||||
connections
|
||||
connections,
|
||||
level: parsedNode.level || 0
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error.code !== 'ENOENT') {
|
||||
|
|
@ -229,7 +230,8 @@ export class FileSystemStorage extends BaseStorage {
|
|||
allNodes.push({
|
||||
id: parsedNode.id,
|
||||
vector: parsedNode.vector,
|
||||
connections
|
||||
connections,
|
||||
level: parsedNode.level || 0
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -273,7 +275,8 @@ export class FileSystemStorage extends BaseStorage {
|
|||
nouns.push({
|
||||
id: parsedNode.id,
|
||||
vector: parsedNode.vector,
|
||||
connections
|
||||
connections,
|
||||
level: parsedNode.level || 0
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -575,6 +578,10 @@ export class FileSystemStorage extends BaseStorage {
|
|||
|
||||
// Remove all files in the index directory
|
||||
await removeDirectoryContents(this.indexDir)
|
||||
|
||||
// Clear the statistics cache
|
||||
this.statisticsCache = null
|
||||
this.statisticsModified = false
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ export class MemoryStorage extends BaseStorage {
|
|||
const nounCopy: HNSWNoun = {
|
||||
id: noun.id,
|
||||
vector: [...noun.vector],
|
||||
connections: new Map()
|
||||
connections: new Map(),
|
||||
level: noun.level || 0
|
||||
}
|
||||
|
||||
// Copy connections
|
||||
|
|
@ -70,7 +71,8 @@ export class MemoryStorage extends BaseStorage {
|
|||
const nounCopy: HNSWNoun = {
|
||||
id: noun.id,
|
||||
vector: [...noun.vector],
|
||||
connections: new Map()
|
||||
connections: new Map(),
|
||||
level: noun.level || 0
|
||||
}
|
||||
|
||||
// Copy connections
|
||||
|
|
@ -93,7 +95,8 @@ export class MemoryStorage extends BaseStorage {
|
|||
const nounCopy: HNSWNoun = {
|
||||
id: noun.id,
|
||||
vector: [...noun.vector],
|
||||
connections: new Map()
|
||||
connections: new Map(),
|
||||
level: noun.level || 0
|
||||
}
|
||||
|
||||
// Copy connections
|
||||
|
|
@ -193,7 +196,8 @@ export class MemoryStorage extends BaseStorage {
|
|||
const nounCopy: HNSWNoun = {
|
||||
id: noun.id,
|
||||
vector: [...noun.vector],
|
||||
connections: new Map()
|
||||
connections: new Map(),
|
||||
level: noun.level || 0
|
||||
}
|
||||
|
||||
// Copy connections
|
||||
|
|
@ -578,6 +582,10 @@ export class MemoryStorage extends BaseStorage {
|
|||
this.nounMetadata.clear()
|
||||
this.verbMetadata.clear()
|
||||
this.statistics = null
|
||||
|
||||
// Clear the statistics cache
|
||||
this.statisticsCache = null
|
||||
this.statisticsModified = false
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -224,7 +224,8 @@ export class OPFSStorage extends BaseStorage {
|
|||
return {
|
||||
id: data.id,
|
||||
vector: data.vector,
|
||||
connections
|
||||
connections,
|
||||
level: data.level || 0
|
||||
}
|
||||
} catch (error) {
|
||||
// Noun not found or other error
|
||||
|
|
@ -258,7 +259,8 @@ export class OPFSStorage extends BaseStorage {
|
|||
allNouns.push({
|
||||
id: data.id,
|
||||
vector: data.vector,
|
||||
connections
|
||||
connections,
|
||||
level: data.level || 0
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(`Error reading noun file ${name}:`, error)
|
||||
|
|
@ -315,7 +317,8 @@ export class OPFSStorage extends BaseStorage {
|
|||
nodes.push({
|
||||
id: data.id,
|
||||
vector: data.vector,
|
||||
connections
|
||||
connections,
|
||||
level: data.level || 0
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
@ -732,6 +735,10 @@ export class OPFSStorage extends BaseStorage {
|
|||
|
||||
// Remove all files in the index directory
|
||||
await removeDirectoryContents(this.indexDir!)
|
||||
|
||||
// Clear the statistics cache
|
||||
this.statisticsCache = null
|
||||
this.statisticsModified = false
|
||||
} catch (error) {
|
||||
console.error('Error clearing storage:', error)
|
||||
throw error
|
||||
|
|
|
|||
|
|
@ -440,7 +440,8 @@ export class S3CompatibleStorage extends BaseStorage {
|
|||
const node = {
|
||||
id: parsedNode.id,
|
||||
vector: parsedNode.vector,
|
||||
connections
|
||||
connections,
|
||||
level: parsedNode.level || 0
|
||||
}
|
||||
|
||||
console.log(`Successfully retrieved node ${id}:`, node)
|
||||
|
|
@ -1585,6 +1586,10 @@ export class S3CompatibleStorage extends BaseStorage {
|
|||
|
||||
// Delete all objects in the index directory
|
||||
await deleteObjectsWithPrefix(this.indexPrefix)
|
||||
|
||||
// Clear the statistics cache
|
||||
this.statisticsCache = null
|
||||
this.statisticsModified = false
|
||||
} catch (error) {
|
||||
console.error('Failed to clear storage:', error)
|
||||
throw new Error(`Failed to clear storage: ${error}`)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
* - Level 3: Cold storage (all nodes) - OPFS, Filesystem or S3 depending on environment
|
||||
*/
|
||||
|
||||
import { HNSWNoun, GraphVerb } from '../coreTypes.js'
|
||||
import { HNSWNoun, GraphVerb, HNSWVerb } from '../coreTypes.js'
|
||||
import { BrainyError } from '../errors/brainyError.js'
|
||||
|
||||
// Extend Navigator interface to include deviceMemory property
|
||||
|
|
@ -71,7 +71,7 @@ enum StorageType {
|
|||
/**
|
||||
* Multi-level cache manager for efficient data access
|
||||
*/
|
||||
export class CacheManager<T extends HNSWNode | Edge> {
|
||||
export class CacheManager<T extends HNSWNode | Edge | HNSWVerb> {
|
||||
// Hot cache (RAM)
|
||||
private hotCache = new Map<string, CacheEntry<T>>()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue