refactor(8.0): final cleanup — drop HnswProvider alias + config.hnsw + 'hnsw' surface (scaffold step 6)
Step 6 of the brainy 8.0 rename scaffolding. Removes every legacy 'hnsw'-
flavoured public name introduced as a compat shim in steps 1-5. The
algorithm-neutral surface is now the only surface.
REMOVED — PHASE A (type aliases)
src/plugin.ts
- Removed `export type HnswProvider = VectorIndexProvider` alias.
- Removed `export type DiskAnnProvider = VectorIndexProvider` alias.
src/index.ts
- Removed `export const HNSWIndex = JsHnswVectorIndex` alias.
src/types/brainy.types.ts
- Removed `BrainyStats.indexHealth.hnsw` field (the new `vector` field
carries the same boolean).
src/brainy.ts
- `stats()` no longer emits the legacy `hnsw` field on `indexHealth`.
REMOVED — PHASE B (storage adapter rename, 8 adapters)
Repo-wide rename: `saveHNSWData` → `saveVectorIndexData` and
`getHNSWData` → `getVectorIndexData` across:
- src/storage/adapters/baseStorageAdapter.ts (abstract declarations)
- src/storage/adapters/fileSystemStorage.ts
- src/storage/adapters/gcsStorage.ts
- src/storage/adapters/r2Storage.ts
- src/storage/adapters/s3CompatibleStorage.ts
- src/storage/adapters/azureBlobStorage.ts
- src/storage/adapters/opfsStorage.ts
- src/storage/adapters/memoryStorage.ts
- src/storage/adapters/historicalStorageAdapter.ts
- src/brainy.ts (call sites)
- src/hnsw/hnswIndex.ts + src/hnsw/typeAwareHNSWIndex.ts (call sites)
The default-delegation wrappers added in scaffold step 4 are removed
(would have been duplicate declarations after the rename).
REMOVED — PHASE C (cache category 'hnsw')
src/utils/unifiedCache.ts
- Cache-category union narrowed from
'hnsw' | 'vectors' | 'metadata' | 'embedding' | 'other'
to
'vectors' | 'metadata' | 'embedding' | 'other'
- typeAccessCounts, typeSizes, typeCounts, accessRatios, sizeRatios,
and the fairness-check iterator all drop the 'hnsw' key.
- Per planning § 2.5: pre-8.0 'hnsw' cache entries are an in-memory
category. Cache is rebuildable; entries naturally don't exist after
a restart, so no migration path is needed.
src/hnsw/hnswIndex.ts
- 3 cache.set() call sites migrated from category 'hnsw' to 'vectors'.
- Cache key prefix `hnsw:vector:` → `vector:`.
- typeCounts/typeSizes/typeAccessCounts accessor renames
`.hnsw` → `.vectors`.
tests/unit/utils/unifiedCache-eviction.test.ts
- Test fixtures updated: cache.set(..., 'hnsw', ...) → cache.set(..., 'vectors', ...).
- Stats assertion `stats.typeSizes.hnsw` → `stats.typeSizes.vectors`.
REMOVED — PHASE D (config.hnsw)
src/types/brainy.types.ts
- Removed `BrainyConfig.hnsw` field entirely. The 8.0 surface is
`BrainyConfig.vector.{recall, quantization, vectorStorage, advanced}`.
src/brainy.ts
- normalizeConfig() no longer emits a `hnsw` field on Required<BrainyConfig>.
- setupIndex() rewired:
- Reads from `this.config.vector` (not `this.config.hnsw`).
- Calls `resolveJsHnswConfig(this.config.vector)` to translate the
`recall` preset into M / efConstruction / efSearch knobs (with
`advanced.hnsw` overrides winning when supplied).
- Imports `resolveJsHnswConfig` from './utils/recallPreset.js'.
NOT IN THIS COMMIT (deliberately)
- Persisted file path migration `_system/hnsw-*.json` →
`_system/vector-index-*.json`. Requires dual-read logic on boot
across 8 storage adapters. Per integration doc lines 531-539:
"Reader accepts either spelling on load; writer emits the new spelling
only; brains self-migrate on the next persist after upgrade." This is
a separate body of work and lands in a follow-up commit before 8.0 GA.
- `config.hnswPersistMode` top-level field is unchanged. It's not in
the rename inventory; a future commit can fold it into
`config.vector.persistMode` if desired.
- strictConfig enforcement wiring. The field is accepted by
normalizeConfig() with default 'warn'; the actual warning emission at
knob-mismatch sites lands when the config-resolution layer is touched
for the persisted-path migration.
VERIFICATION
- npx tsc --noEmit: clean
- npm test: 1468 / 1468 unit (one test fixture updated to use the new
category name; assertion still passes after fixture rename)
- npm run build: clean
The 8.0 PR's user-facing surface is now algorithm-neutral end-to-end:
VectorIndexProvider, config.vector.recall, JsHnswVectorIndex,
saveVectorIndexData, 'vectors' cache category, indexHealth.vector,
strictConfig — all standalone. No legacy 'hnsw' name remains in any
public type or method signature.
This commit is contained in:
parent
3e1ef957bc
commit
b20666e020
17 changed files with 76 additions and 145 deletions
|
|
@ -1768,7 +1768,7 @@ export class AzureBlobStorage extends BaseStorage {
|
|||
* Uses BaseStorage's getNoun/saveNoun (type-first paths)
|
||||
* CRITICAL: Uses mutex locking to prevent read-modify-write races
|
||||
*/
|
||||
public async saveHNSWData(nounId: string, hnswData: {
|
||||
public async saveVectorIndexData(nounId: string, hnswData: {
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
}): Promise<void> {
|
||||
|
|
@ -1829,7 +1829,7 @@ export class AzureBlobStorage extends BaseStorage {
|
|||
* Get HNSW graph data for a noun
|
||||
* Uses BaseStorage's getNoun (type-first paths)
|
||||
*/
|
||||
public async getHNSWData(nounId: string): Promise<{
|
||||
public async getVectorIndexData(nounId: string): Promise<{
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
} | null> {
|
||||
|
|
|
|||
|
|
@ -95,49 +95,24 @@ export abstract class BaseStorageAdapter implements StorageAdapter {
|
|||
|
||||
abstract getVerbMetadata(id: string): Promise<any | null>
|
||||
|
||||
// Vector Index Persistence (Brainy 8.0 — algorithm-neutral surface)
|
||||
// The legacy `saveHNSWData` / `getHNSWData` names persist as default-method
|
||||
// aliases so existing implementations continue to work mid-migration; the
|
||||
// 8.0 final cleanup commit removes the old names.
|
||||
// Vector Index Persistence (Brainy 8.0 — algorithm-neutral surface).
|
||||
// Concrete adapters persist the per-entity HNSW graph node (level + connections)
|
||||
// under these methods. Cortex's DiskANN-style native vector index doesn't use
|
||||
// them (it persists its own single mmap'd `.dkann` file under
|
||||
// `_system/vector-index/<shard>.dkann` per BRAINY-8.0-RENAME-COORDINATION § B.2).
|
||||
|
||||
abstract getNounVector(id: string): Promise<number[] | null>
|
||||
|
||||
abstract saveHNSWData(nounId: string, hnswData: {
|
||||
abstract saveVectorIndexData(nounId: string, data: {
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
}): Promise<void>
|
||||
|
||||
abstract getHNSWData(nounId: string): Promise<{
|
||||
abstract getVectorIndexData(nounId: string): Promise<{
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
} | null>
|
||||
|
||||
/**
|
||||
* Persist vector-index graph state for an entity (Brainy 8.0 name).
|
||||
* Default implementation delegates to {@link saveHNSWData}; concrete
|
||||
* adapters may override directly. The final 8.0 cleanup removes the
|
||||
* legacy `saveHNSWData` name.
|
||||
*/
|
||||
async saveVectorIndexData(nounId: string, data: {
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
}): Promise<void> {
|
||||
return this.saveHNSWData(nounId, data)
|
||||
}
|
||||
|
||||
/**
|
||||
* Read vector-index graph state for an entity (Brainy 8.0 name).
|
||||
* Default implementation delegates to {@link getHNSWData}; concrete
|
||||
* adapters may override directly. The final 8.0 cleanup removes the
|
||||
* legacy `getHNSWData` name.
|
||||
*/
|
||||
async getVectorIndexData(nounId: string): Promise<{
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
} | null> {
|
||||
return this.getHNSWData(nounId)
|
||||
}
|
||||
|
||||
abstract saveHNSWSystem(systemData: {
|
||||
entryPointId: string | null
|
||||
maxLevel: number
|
||||
|
|
|
|||
|
|
@ -2810,7 +2810,7 @@ export class FileSystemStorage extends BaseStorage {
|
|||
* Uses BaseStorage's getNoun/saveNoun (type-first paths)
|
||||
* CRITICAL: Preserves mutex locking to prevent read-modify-write races
|
||||
*/
|
||||
public async saveHNSWData(nounId: string, hnswData: {
|
||||
public async saveVectorIndexData(nounId: string, hnswData: {
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
}): Promise<void> {
|
||||
|
|
@ -2871,7 +2871,7 @@ export class FileSystemStorage extends BaseStorage {
|
|||
* Get HNSW graph data for a noun
|
||||
* Uses BaseStorage's getNoun (type-first paths)
|
||||
*/
|
||||
public async getHNSWData(nounId: string): Promise<{
|
||||
public async getVectorIndexData(nounId: string): Promise<{
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
} | null> {
|
||||
|
|
|
|||
|
|
@ -1736,7 +1736,7 @@ export class GcsStorage extends BaseStorage {
|
|||
* Uses BaseStorage's getNoun/saveNoun (type-first paths)
|
||||
* CRITICAL: Uses mutex locking to prevent read-modify-write races
|
||||
*/
|
||||
public async saveHNSWData(nounId: string, hnswData: {
|
||||
public async saveVectorIndexData(nounId: string, hnswData: {
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
}): Promise<void> {
|
||||
|
|
@ -1797,7 +1797,7 @@ export class GcsStorage extends BaseStorage {
|
|||
* Get HNSW graph data for a noun
|
||||
* Uses BaseStorage's getNoun (type-first paths)
|
||||
*/
|
||||
public async getHNSWData(nounId: string): Promise<{
|
||||
public async getVectorIndexData(nounId: string): Promise<{
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
} | null> {
|
||||
|
|
|
|||
|
|
@ -462,7 +462,7 @@ export class HistoricalStorageAdapter extends BaseStorage {
|
|||
/**
|
||||
* WRITE BLOCKED: Historical storage is read-only
|
||||
*/
|
||||
public async saveHNSWData(nounId: string, hnswData: {
|
||||
public async saveVectorIndexData(nounId: string, hnswData: {
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
}): Promise<void> {
|
||||
|
|
@ -492,7 +492,7 @@ export class HistoricalStorageAdapter extends BaseStorage {
|
|||
/**
|
||||
* Get HNSW data from historical state
|
||||
*/
|
||||
public async getHNSWData(nounId: string): Promise<{
|
||||
public async getVectorIndexData(nounId: string): Promise<{
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
} | null> {
|
||||
|
|
|
|||
|
|
@ -415,7 +415,7 @@ export class MemoryStorage extends BaseStorage {
|
|||
* Even in-memory operations can race due to async/await interleaving
|
||||
* Prevents data corruption when multiple entities connect to same neighbor simultaneously
|
||||
*/
|
||||
public async saveHNSWData(nounId: string, hnswData: {
|
||||
public async saveVectorIndexData(nounId: string, hnswData: {
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
}): Promise<void> {
|
||||
|
|
@ -458,7 +458,7 @@ export class MemoryStorage extends BaseStorage {
|
|||
/**
|
||||
* Get HNSW graph data for a noun
|
||||
*/
|
||||
public async getHNSWData(nounId: string): Promise<{
|
||||
public async getVectorIndexData(nounId: string): Promise<{
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
} | null> {
|
||||
|
|
|
|||
|
|
@ -1453,7 +1453,7 @@ export class OPFSStorage extends BaseStorage {
|
|||
* Uses BaseStorage's getNoun/saveNoun (type-first paths)
|
||||
* CRITICAL: Preserves mutex locking to prevent read-modify-write races
|
||||
*/
|
||||
public async saveHNSWData(nounId: string, hnswData: {
|
||||
public async saveVectorIndexData(nounId: string, hnswData: {
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
}): Promise<void> {
|
||||
|
|
@ -1503,7 +1503,7 @@ export class OPFSStorage extends BaseStorage {
|
|||
* Get HNSW graph data for a noun
|
||||
* Uses BaseStorage's getNoun (type-first paths)
|
||||
*/
|
||||
public async getHNSWData(nounId: string): Promise<{
|
||||
public async getVectorIndexData(nounId: string): Promise<{
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
} | null> {
|
||||
|
|
|
|||
|
|
@ -1090,7 +1090,7 @@ export class R2Storage extends BaseStorage {
|
|||
return noun ? noun.vector : null
|
||||
}
|
||||
|
||||
public async saveHNSWData(nounId: string, hnswData: {
|
||||
public async saveVectorIndexData(nounId: string, hnswData: {
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
}): Promise<void> {
|
||||
|
|
@ -1130,7 +1130,7 @@ export class R2Storage extends BaseStorage {
|
|||
}
|
||||
}
|
||||
|
||||
public async getHNSWData(nounId: string): Promise<{
|
||||
public async getVectorIndexData(nounId: string): Promise<{
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
} | null> {
|
||||
|
|
|
|||
|
|
@ -3723,7 +3723,7 @@ export class S3CompatibleStorage extends BaseStorage {
|
|||
* Uses BaseStorage's getNoun/saveNoun (type-first paths)
|
||||
* CRITICAL: Uses mutex locking to prevent read-modify-write races
|
||||
*/
|
||||
public async saveHNSWData(nounId: string, hnswData: {
|
||||
public async saveVectorIndexData(nounId: string, hnswData: {
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
}): Promise<void> {
|
||||
|
|
@ -3784,7 +3784,7 @@ export class S3CompatibleStorage extends BaseStorage {
|
|||
* Get HNSW graph data for a noun
|
||||
* Uses BaseStorage's getNoun (type-first paths)
|
||||
*/
|
||||
public async getHNSWData(nounId: string): Promise<{
|
||||
public async getVectorIndexData(nounId: string): Promise<{
|
||||
level: number
|
||||
connections: Record<string, string[]>
|
||||
} | null> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue