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
649e452ff9
commit
cfaf2f8b83
12 changed files with 668 additions and 112 deletions
|
|
@ -140,7 +140,8 @@ export class HNSWIndex {
|
|||
const noun: HNSWNoun = {
|
||||
id,
|
||||
vector,
|
||||
connections: new Map()
|
||||
connections: new Map(),
|
||||
level: nounLevel
|
||||
}
|
||||
|
||||
// Initialize empty connection sets for each level
|
||||
|
|
@ -558,6 +559,38 @@ export class HNSWIndex {
|
|||
return { ...this.config }
|
||||
}
|
||||
|
||||
/**
|
||||
* Get index health metrics
|
||||
*/
|
||||
public getIndexHealth(): {
|
||||
averageConnections: number
|
||||
layerDistribution: number[]
|
||||
maxLayer: number
|
||||
totalNodes: number
|
||||
} {
|
||||
let totalConnections = 0
|
||||
const layerCounts = new Array(this.maxLevel + 1).fill(0)
|
||||
|
||||
// Count connections and layer distribution
|
||||
this.nouns.forEach(noun => {
|
||||
// Count connections at each layer
|
||||
for (let level = 0; level <= noun.level; level++) {
|
||||
totalConnections += noun.connections.get(level)?.size || 0
|
||||
layerCounts[level]++
|
||||
}
|
||||
})
|
||||
|
||||
const totalNodes = this.nouns.size
|
||||
const averageConnections = totalNodes > 0 ? totalConnections / totalNodes : 0
|
||||
|
||||
return {
|
||||
averageConnections,
|
||||
layerDistribution: layerCounts,
|
||||
maxLayer: this.maxLevel,
|
||||
totalNodes
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search within a specific layer
|
||||
* Returns a map of noun IDs to distances, sorted by distance
|
||||
|
|
|
|||
|
|
@ -411,7 +411,8 @@ export class HNSWIndexOptimized extends HNSWIndex {
|
|||
const noun: HNSWNoun = {
|
||||
id,
|
||||
vector,
|
||||
connections: new Map()
|
||||
connections: new Map(),
|
||||
level: 0
|
||||
}
|
||||
|
||||
// Store the noun
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue