/** * Write-Ahead Log (WAL) for Incremental Index Updates * * Provides durability and efficient incremental writes for HNSW index operations. * Instead of rewriting the entire index on each update, operations are appended * to a log file. The log can be compacted into a full snapshot periodically. * * Benefits: * - Fast appends (no full serialization) * - Crash recovery (replay log after restart) * - Reduced I/O for frequent updates */ import type { StorageBackend } from './StorageBackend.js'; export declare enum WALOperationType { ADD_VECTOR = 1, ADD_NEIGHBORS = 2, UPDATE_ENTRY_POINT = 3, CHECKPOINT = 4 } export interface WALEntry { type: WALOperationType; timestamp: number; data: ArrayBuffer; } /** * WriteAheadLog - Append-only log for incremental index updates */ export declare class WriteAheadLog { private storage; private logKey; private pendingEntries; private flushThreshold; private entryCount; private operationLock; /** * Create a new WAL * @param storage StorageBackend for persistence * @param logKey Storage key for the WAL data (e.g., "myindex.wal") * @param flushThreshold Number of entries before auto-flush (default: 100) */ constructor(storage: StorageBackend, logKey: string, flushThreshold?: number); private withOperationLock; /** * Get the WAL storage key */ getKey(): string; /** * Check if WAL data exists */ exists(): Promise; /** * Append a vector addition operation to the log */ appendVector(id: number, vector: Float32Array): Promise; /** * Append a neighbor update operation to the log */ appendNeighbors(nodeId: number, layer: number, neighbors: number[]): Promise; /** * Append entry point update to the log */ appendEntryPointUpdate(entryPointId: number, maxLevel: number): Promise; /** * Write a checkpoint marker to the log */ checkpoint(): Promise; private appendEntry; /** * Serialize a WAL entry to bytes */ private serializeEntry; /** * Flush pending entries to storage * Uses append for efficient O(1) writes */ flush(): Promise; private flushInternal; private flushEntries; /** * Read all entries from the WAL */ readEntries(): Promise; /** * Parse a vector addition entry */ static parseVectorEntry(data: ArrayBuffer): { id: number; vector: Float32Array; }; /** * Parse a neighbor update entry */ static parseNeighborsEntry(data: ArrayBuffer): { nodeId: number; layer: number; neighbors: number[]; }; /** * Parse an entry point update entry */ static parseEntryPointEntry(data: ArrayBuffer): { entryPointId: number; maxLevel: number; }; /** * Get entry count since last compact */ getEntryCount(): number; /** * Clear the WAL (after successful compaction) */ clear(): Promise; /** * Delete the WAL data */ delete(): Promise; } //# sourceMappingURL=WriteAheadLog.d.ts.map