UNPKG

lsh-index

Version:

Locality-Sensitive Hashing implementation for indexing vectors using random projections

37 lines (36 loc) 935 B
export interface LSHOptions { dimensions: number; numProjections: number; numBands: number; bucketSize?: number; distanceMetric?: (v1: number[], v2: number[]) => number; } export declare class LSH { private options; private projectionVectors; private buckets; private vectors; private readonly bucketSize; private readonly rowsPerBand; private distanceMetric; constructor(options: LSHOptions); private initializeProjections; private projectVector; private getBucketHash; insert(params: { id: string; vector: number[]; }): void; query(params: { vector: number[]; maxDistance: number; }): string[]; private euclideanDistance; clear(): void; export(): { options: LSHOptions; projectionVectors: number[][]; buckets: (string | string[])[][][]; vectors: [string, number[]][]; }; }