chore: recovery checkpoint - v3.0 API successfully recovered
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
This commit is contained in:
parent
f65455fb22
commit
8ff382ca3b
895 changed files with 143654 additions and 28268 deletions
134
.recovery-workspace/dist-backup-20250910-141917/hnsw/hnswIndex.d.ts
vendored
Normal file
134
.recovery-workspace/dist-backup-20250910-141917/hnsw/hnswIndex.d.ts
vendored
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
/**
|
||||
* HNSW (Hierarchical Navigable Small World) Index implementation
|
||||
* Based on the paper: "Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs"
|
||||
*/
|
||||
import { DistanceFunction, HNSWConfig, HNSWNoun, Vector, VectorDocument } from '../coreTypes.js';
|
||||
export declare class HNSWIndex {
|
||||
private nouns;
|
||||
private entryPointId;
|
||||
private maxLevel;
|
||||
private config;
|
||||
private distanceFunction;
|
||||
private dimension;
|
||||
private useParallelization;
|
||||
constructor(config?: Partial<HNSWConfig>, distanceFunction?: DistanceFunction, options?: {
|
||||
useParallelization?: boolean;
|
||||
});
|
||||
/**
|
||||
* Set whether to use parallelization for performance-critical operations
|
||||
*/
|
||||
setUseParallelization(useParallelization: boolean): void;
|
||||
/**
|
||||
* Get whether parallelization is enabled
|
||||
*/
|
||||
getUseParallelization(): boolean;
|
||||
/**
|
||||
* Calculate distances between a query vector and multiple vectors in parallel
|
||||
* This is used to optimize performance for search operations
|
||||
* Uses optimized batch processing for optimal performance
|
||||
*
|
||||
* @param queryVector The query vector
|
||||
* @param vectors Array of vectors to compare against
|
||||
* @returns Array of distances
|
||||
*/
|
||||
private calculateDistancesInParallel;
|
||||
/**
|
||||
* Add a vector to the index
|
||||
*/
|
||||
addItem(item: VectorDocument): Promise<string>;
|
||||
/**
|
||||
* Search for nearest neighbors
|
||||
*/
|
||||
search(queryVector: Vector, k?: number, filter?: (id: string) => Promise<boolean>): Promise<Array<[string, number]>>;
|
||||
/**
|
||||
* Remove an item from the index
|
||||
*/
|
||||
removeItem(id: string): boolean;
|
||||
/**
|
||||
* Get all nouns in the index
|
||||
* @deprecated Use getNounsPaginated() instead for better scalability
|
||||
*/
|
||||
getNouns(): Map<string, HNSWNoun>;
|
||||
/**
|
||||
* Get nouns with pagination
|
||||
* @param options Pagination options
|
||||
* @returns Object containing paginated nouns and pagination info
|
||||
*/
|
||||
getNounsPaginated(options?: {
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
filter?: (noun: HNSWNoun) => boolean;
|
||||
}): {
|
||||
items: Map<string, HNSWNoun>;
|
||||
totalCount: number;
|
||||
hasMore: boolean;
|
||||
};
|
||||
/**
|
||||
* Clear the index
|
||||
*/
|
||||
clear(): void;
|
||||
/**
|
||||
* Get the size of the index
|
||||
*/
|
||||
size(): number;
|
||||
/**
|
||||
* Get the distance function used by the index
|
||||
*/
|
||||
getDistanceFunction(): DistanceFunction;
|
||||
/**
|
||||
* Get the entry point ID
|
||||
*/
|
||||
getEntryPointId(): string | null;
|
||||
/**
|
||||
* Get the maximum level
|
||||
*/
|
||||
getMaxLevel(): number;
|
||||
/**
|
||||
* Get the dimension
|
||||
*/
|
||||
getDimension(): number | null;
|
||||
/**
|
||||
* Get the configuration
|
||||
*/
|
||||
getConfig(): HNSWConfig;
|
||||
/**
|
||||
* Get all nodes at a specific level for clustering
|
||||
* This enables O(n) clustering using HNSW's natural hierarchy
|
||||
*/
|
||||
getNodesAtLevel(level: number): HNSWNoun[];
|
||||
/**
|
||||
* Get level statistics for understanding the hierarchy
|
||||
*/
|
||||
getLevelStats(): Array<{
|
||||
level: number;
|
||||
nodeCount: number;
|
||||
avgConnections: number;
|
||||
}>;
|
||||
/**
|
||||
* Get index health metrics
|
||||
*/
|
||||
getIndexHealth(): {
|
||||
averageConnections: number;
|
||||
layerDistribution: number[];
|
||||
maxLayer: number;
|
||||
totalNodes: number;
|
||||
};
|
||||
/**
|
||||
* Search within a specific layer
|
||||
* Returns a map of noun IDs to distances, sorted by distance
|
||||
*/
|
||||
private searchLayer;
|
||||
/**
|
||||
* Select M nearest neighbors from the candidate set
|
||||
*/
|
||||
private selectNeighbors;
|
||||
/**
|
||||
* Ensure a noun doesn't have too many connections at a given level
|
||||
*/
|
||||
private pruneConnections;
|
||||
/**
|
||||
* Generate a random level for a new noun
|
||||
* Uses the same distribution as in the original HNSW paper
|
||||
*/
|
||||
private getRandomLevel;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue