CRITICAL CHECKPOINT - DO NOT PUSH TO GITHUB Recovery Status: - Successfully recovered brainy.ts from compiled JavaScript - All core v3.0 API methods functional (add, get, update, delete, relate, find, etc.) - Neural subsystem intact (562KB embedded patterns, NLP working) - Augmentation pipeline operational (20+ augmentations) - HNSW clustering system complete - Triple Intelligence compiled (needs constructor fix) - Test suite validates functionality Changes preserved: - 898 files with changes from last 3 days - 144,475 insertions - All augmentation improvements - All test coverage enhancements - Complete v3.0 feature set This is a LOCAL checkpoint only - contains recovered work after corruption incident. Created backup in .backups/brainy-full-20250910-151314.tar.gz Branch: recovery-checkpoint-20250910-151433 Date: Wed Sep 10 03:18:04 PM PDT 2025
118 lines
3.2 KiB
TypeScript
118 lines
3.2 KiB
TypeScript
/**
|
|
* Distributed Search System for Large-Scale HNSW Indices
|
|
* Implements parallel search across multiple partitions and instances
|
|
*/
|
|
import { Vector } from '../coreTypes.js';
|
|
import { PartitionedHNSWIndex } from './partitionedHNSWIndex.js';
|
|
interface DistributedSearchConfig {
|
|
maxConcurrentSearches?: number;
|
|
searchTimeout?: number;
|
|
resultMergeStrategy?: 'distance' | 'score' | 'hybrid';
|
|
adaptivePartitionSelection?: boolean;
|
|
redundantSearches?: number;
|
|
loadBalancing?: boolean;
|
|
}
|
|
export declare enum SearchStrategy {
|
|
BROADCAST = "broadcast",// Search all partitions
|
|
SELECTIVE = "selective",// Search subset of partitions
|
|
ADAPTIVE = "adaptive",// Dynamically adjust based on results
|
|
HIERARCHICAL = "hierarchical"
|
|
}
|
|
interface SearchWorker {
|
|
id: string;
|
|
busy: boolean;
|
|
tasksCompleted: number;
|
|
averageTaskTime: number;
|
|
lastTaskTime: number;
|
|
}
|
|
/**
|
|
* Distributed search coordinator for large-scale vector search
|
|
*/
|
|
export declare class DistributedSearchSystem {
|
|
private config;
|
|
private searchWorkers;
|
|
private searchQueue;
|
|
private activeSearches;
|
|
private partitionStats;
|
|
private searchStats;
|
|
constructor(config?: Partial<DistributedSearchConfig>);
|
|
/**
|
|
* Execute distributed search across multiple partitions
|
|
*/
|
|
distributedSearch(partitionedIndex: PartitionedHNSWIndex, queryVector: Vector, k: number, strategy?: SearchStrategy): Promise<Array<[string, number]>>;
|
|
/**
|
|
* Select partitions to search based on strategy
|
|
*/
|
|
private selectPartitions;
|
|
/**
|
|
* Adaptive partition selection based on historical performance
|
|
*/
|
|
private adaptivePartitionSelection;
|
|
/**
|
|
* Select top-performing partitions
|
|
*/
|
|
private selectTopPartitions;
|
|
/**
|
|
* Hierarchical partition selection for very large datasets
|
|
*/
|
|
private hierarchicalPartitionSelection;
|
|
/**
|
|
* Create search tasks for parallel execution
|
|
*/
|
|
private createSearchTasks;
|
|
/**
|
|
* Execute searches in parallel across selected partitions
|
|
*/
|
|
private executeParallelSearches;
|
|
/**
|
|
* Execute search on a single partition
|
|
*/
|
|
private executePartitionSearch;
|
|
/**
|
|
* Determine if search should use worker thread
|
|
*/
|
|
private shouldUseWorkerThread;
|
|
/**
|
|
* Execute search in worker thread
|
|
*/
|
|
private executeInWorkerThread;
|
|
/**
|
|
* Get available worker from pool
|
|
*/
|
|
private getAvailableWorker;
|
|
/**
|
|
* Merge search results from multiple partitions
|
|
*/
|
|
private mergeSearchResults;
|
|
/**
|
|
* Get partition quality score
|
|
*/
|
|
private getPartitionQuality;
|
|
/**
|
|
* Update search statistics
|
|
*/
|
|
private updateSearchStats;
|
|
/**
|
|
* Initialize worker thread pool
|
|
*/
|
|
private initializeWorkerPool;
|
|
/**
|
|
* Generate unique search ID
|
|
*/
|
|
private generateSearchId;
|
|
/**
|
|
* Get search performance statistics
|
|
*/
|
|
getSearchStats(): typeof this.searchStats & {
|
|
workerStats: SearchWorker[];
|
|
partitionStats: Array<{
|
|
id: string;
|
|
stats: any;
|
|
}>;
|
|
};
|
|
/**
|
|
* Cleanup resources
|
|
*/
|
|
cleanup(): void;
|
|
}
|
|
export {};
|