HnswGraphSearcher

Searches an HNSW graph to find nearest neighbors to a query vector. For more background on the search algorithm, see HnswGraph.

Inheritors

Constructors

Link copied to clipboard
constructor(candidates: NeighborQueue, visited: BitSet)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun findBestEntryPoint(scorer: RandomVectorScorer, graph: HnswGraph, collector: KnnCollector): IntArray

Function to find the best entry point from which to search the zeroth graph layer.

Link copied to clipboard
open fun graphNextNeighbor(graph: HnswGraph): Int

Get the next neighbor from the graph, you must call .graphSeek before calling this method. The default implementation will just call

Link copied to clipboard
open fun graphSeek(graph: HnswGraph, level: Int, targetNode: Int)

Seek a specific node in the given graph. The default implementation will just call

Link copied to clipboard
fun search(results: KnnCollector, scorer: RandomVectorScorer, graph: HnswGraph, acceptOrds: Bits?)

Search the graph for the given scorer. Gathering results in the provided collector that pass the provided acceptOrds.

Link copied to clipboard

Searches for the nearest neighbors of a query vector in a given level.

open override fun searchLevel(results: KnnCollector, scorer: RandomVectorScorer, level: Int, eps: IntArray, graph: HnswGraph, acceptOrds: Bits?)

Add the closest neighbors found to a priority queue (heap). These are returned in REVERSE proximity order -- the most distant neighbor of the topK found, i.e. the one with the lowest score/comparison value, will be at the top of the heap, while the closest neighbor will be the last to be popped.