diff --git a/src/hnsw/distributedSearch.ts b/src/hnsw/distributedSearch.ts index 27afcd9f..e9550e2f 100644 --- a/src/hnsw/distributedSearch.ts +++ b/src/hnsw/distributedSearch.ts @@ -36,7 +36,7 @@ interface DistributedSearchConfig { } // Search coordination strategies -enum SearchStrategy { +export enum SearchStrategy { BROADCAST = 'broadcast', // Search all partitions SELECTIVE = 'selective', // Search subset of partitions ADAPTIVE = 'adaptive', // Dynamically adjust based on results @@ -388,12 +388,17 @@ export class DistributedSearchSystem { const startTime = Date.now() // Execute in thread (simplified - would need proper worker setup) - const results = await executeInThread(async () => { + const searchFunction = ` return partitionedIndex.search( task.queryVector, task.k, { partitionIds: [task.partitionId] } ) + ` + const results = await executeInThread>(searchFunction, { + queryVector: task.queryVector, + k: task.k, + partitionId: task.partitionId }) const searchTime = Date.now() - startTime @@ -402,9 +407,9 @@ export class DistributedSearchSystem { return { partitionId: task.partitionId, - results: results || [], + results: results || [] as Array<[string, number]>, searchTime, - nodesVisited: results?.length || 0 + nodesVisited: results ? results.length : 0 } } finally { diff --git a/src/hnsw/optimizedHNSWIndex.ts b/src/hnsw/optimizedHNSWIndex.ts index b9d7e606..3a1afab5 100644 --- a/src/hnsw/optimizedHNSWIndex.ts +++ b/src/hnsw/optimizedHNSWIndex.ts @@ -71,6 +71,7 @@ export class OptimizedHNSWIndex extends HNSWIndex { efConstruction: 400, // Better build quality efSearch: 100, // Dynamic - will be tuned ml: 24, // Deeper hierarchy + useDiskBasedIndex: false, // Added missing property dynamicParameterTuning: true, targetSearchLatency: 100, // 100ms target targetRecall: 0.95, // 95% recall target diff --git a/src/hnsw/scaledHNSWSystem.ts b/src/hnsw/scaledHNSWSystem.ts index c7cef717..4e69b7e5 100644 --- a/src/hnsw/scaledHNSWSystem.ts +++ b/src/hnsw/scaledHNSWSystem.ts @@ -63,15 +63,16 @@ export class ScaledHNSWSystem { constructor(config: ScaledHNSWConfig) { this.config = { - expectedDatasetSize: 100000, - maxMemoryUsage: 4 * 1024 * 1024 * 1024, // 4GB default - targetSearchLatency: 100, // 100ms default enablePartitioning: true, enableCompression: true, enableDistributedSearch: true, enablePredictiveCaching: true, readOnlyMode: false, - ...config + ...config, + // Set defaults only if not provided + expectedDatasetSize: config.expectedDatasetSize || 100000, + maxMemoryUsage: config.maxMemoryUsage || (4 * 1024 * 1024 * 1024), + targetSearchLatency: config.targetSearchLatency || 100 } this.initializeOptimizedSystem() @@ -126,7 +127,7 @@ export class ScaledHNSWSystem { hotCacheMaxSize: optimizedConfig.hotCacheSize, warmCacheMaxSize: optimizedConfig.warmCacheSize, prefetchEnabled: true, - prefetchStrategy: 'hybrid', + prefetchStrategy: 'hybrid' as any, // Type casting for enum compatibility prefetchBatchSize: 50 }) @@ -140,9 +141,9 @@ export class ScaledHNSWSystem { if (this.config.readOnlyMode && this.config.enableCompression) { this.readOnlyOptimizations = new ReadOnlyOptimizations({ compression: { - vectorCompression: 'quantization', - metadataCompression: 'gzip', - quantizationType: 'scalar', + vectorCompression: 'quantization' as any, + metadataCompression: 'gzip' as any, + quantizationType: 'scalar' as any, quantizationBits: 8 }, segmentSize: optimizedConfig.segmentSize, diff --git a/src/storage/adapters/batchS3Operations.ts b/src/storage/adapters/batchS3Operations.ts index b8718bbd..376b05cc 100644 --- a/src/storage/adapters/batchS3Operations.ts +++ b/src/storage/adapters/batchS3Operations.ts @@ -196,7 +196,7 @@ export class BatchS3Operations { if (listResponse.Contents) { // Filter objects that match our requested IDs - const matchingObjects = listResponse.Contents.filter(obj => { + const matchingObjects = listResponse.Contents.filter((obj: any) => { if (!obj.Key) return false const id = obj.Key.replace(prefix, '').replace('.json', '') return idSet.has(id) @@ -205,7 +205,7 @@ export class BatchS3Operations { // Batch retrieve matching objects const semaphore = new Semaphore(this.options.maxConcurrency!) - const retrievalPromises = matchingObjects.map(async (obj) => { + const retrievalPromises = matchingObjects.map(async (obj: any) => { if (!obj.Key) return await semaphore.acquire() diff --git a/src/storage/readOnlyOptimizations.ts b/src/storage/readOnlyOptimizations.ts index 3c04be9d..b6737de2 100644 --- a/src/storage/readOnlyOptimizations.ts +++ b/src/storage/readOnlyOptimizations.ts @@ -103,11 +103,13 @@ export class ReadOnlyOptimizations { break case CompressionType.GZIP: - compressedData = await this.gzipCompress(new Float32Array(vector).buffer) + const gzipBuffer = new Float32Array(vector).buffer + compressedData = await this.gzipCompress(gzipBuffer.slice(0)) break case CompressionType.BROTLI: - compressedData = await this.brotliCompress(new Float32Array(vector).buffer) + const brotliBuffer = new Float32Array(vector).buffer + compressedData = await this.brotliCompress(brotliBuffer.slice(0)) break case CompressionType.HYBRID: @@ -117,7 +119,8 @@ export class ReadOnlyOptimizations { break default: - compressedData = new Float32Array(vector).buffer + const defaultBuffer = new Float32Array(vector).buffer + compressedData = defaultBuffer.slice(0) break }