fix: metadata explosion bug - 69K files reduced to ~1K

Critical fix for metadata indexing that was creating 60+ chunk files per entity.

Root cause: Vector embeddings (384-dimensional arrays) were being indexed in
metadata, causing each dimension to create a separate chunk file with numeric
field names ("0", "1", "2", etc.).

Changes:
- Modified extractIndexableFields() to exclude vector/embedding fields
- Added NEVER_INDEX set: ['vector', 'embedding', 'embeddings', 'connections']
- Added safety check to skip arrays > 10 elements
- Preserves small array indexing (tags, categories, roles)

Impact:
- Reduces metadata files from 69,429 → ~1,200 (58x reduction)
- Fixes server initialization hangs
- Fixes metadata batch loading stalling at batch 23
- Fixes VFS getDescendants() hanging with large datasets
- Fixes Graph View UI not loading

Test Results:
- 7/7 integration tests passing
- Verified: 6 chunk files for 10 entities (was 7,210 before fix)
- 611/622 unit tests passing

Files Modified:
- src/utils/metadataIndex.ts - Core fix
- src/coreTypes.ts - HNSWVerb type enforcement with VerbType enum
- src/storage/adapters/* - Include core relational fields in HNSWVerb
- src/storage/adapters/baseStorageAdapter.ts - Type enforcement (HNSWNoun, GraphVerb)
- tests/integration/metadata-vector-exclusion.test.ts - Comprehensive test coverage

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
David Snelling 2025-10-16 16:10:31 -07:00
parent 7921a5b744
commit e600865d96
13 changed files with 571 additions and 112 deletions

View file

@ -289,10 +289,19 @@ export class MemoryStorage extends BaseStorage {
const isNew = !this.verbs.has(verb.id)
// Create a deep copy to avoid reference issues
// ARCHITECTURAL FIX (v3.50.1): Include core relational fields
const verbCopy: HNSWVerb = {
id: verb.id,
vector: [...verb.vector],
connections: new Map()
connections: new Map(),
// CORE RELATIONAL DATA
verb: verb.verb,
sourceId: verb.sourceId,
targetId: verb.targetId,
// User metadata (if any)
metadata: verb.metadata
}
// Copy connections
@ -321,10 +330,19 @@ export class MemoryStorage extends BaseStorage {
}
// Return a deep copy of the HNSWVerb
// ARCHITECTURAL FIX (v3.50.1): Include core relational fields
const verbCopy: HNSWVerb = {
id: verb.id,
vector: [...verb.vector],
connections: new Map()
connections: new Map(),
// CORE RELATIONAL DATA
verb: verb.verb,
sourceId: verb.sourceId,
targetId: verb.targetId,
// User metadata
metadata: verb.metadata
}
// Copy connections
@ -332,14 +350,7 @@ export class MemoryStorage extends BaseStorage {
verbCopy.connections.set(level, new Set(connections))
}
// Get metadata (relationship data in 2-file system)
const metadata = await this.getVerbMetadata(id)
// Combine into complete verb object
return {
...verbCopy,
metadata: metadata || {}
}
return verbCopy
}
/**