k-NN
k-Nearest Neighbor search - the vector similarity retrieval method used in the memory gateway to find memories whose embeddings are closest to the query embedding. Combined with BM25 keyword search in the hybrid retrieval pipeline. Accelerated by HNSW indexing in OpenSearch.
k-NN retrieval operates in embedding space: given a query, the memory gateway computes an embedding for the query and finds the k memories whose stored embeddings are most similar by cosine or dot-product distance. This captures semantic similarity - memories that discuss related concepts surface even if they share no exact keywords with the query. OpenSearch's k-NN plugin implements this using HNSW indexing in the hot tier, providing approximate nearest neighbor results in milliseconds. The memory gateway's hybrid retrieval combines k-NN results with BM25 keyword results using a weighted fusion step, then optionally re-ranks the merged candidate set with a cross-encoder. The hybrid approach consistently outperforms either method alone: BM25 covers precise term matches that embeddings blur, while k-NN covers semantic relationships that keyword search cannot reach.