LSHIndex<T>

Models & Types · AiDotNet.RetrievalAugmentedGeneration.VectorSearch.Indexes

Locality-Sensitive Hashing (LSH) index for approximate nearest neighbor search.

Implements: IVectorIndex<T>

How It Works

LSH uses hash functions that map similar vectors to the same hash buckets. Multiple hash tables are used to improve recall. During search, only vectors in the same buckets as the query are considered, providing sublinear search time. Search complexity: O(n^ρ) where ρ < 1, depending on parameters. Best for high-dimensional sparse data and when approximate results are acceptable. This is a simplified implementation using random projection for testing.

Constructors

Constructor Summary
LSHIndex(ISimilarityMetric<T> metric, int numHashTables, int numHashFunctions, int seed) Initializes a new instance of the LSHIndex class.

Properties

Property Summary
int Count { get; }

Methods

Method Summary
List<ValueTuple<string, T>> Search(Vector<T> query, int k)
bool Remove(string id)
void Add(string id, Vector<T> vector)
void AddBatch(Dictionary<string, Vector<T>> vectors)
void Clear()