jruby/docs BETA
org.apache.lucene.util.hnsw 32
C AbstractRandomVectorScorer
C AbstractUpdateableRandomVectorScorer
C ArrayNodesIterator
C BlockingFloatHeap
I CloseableRandomVectorScorerSupplier
C CollectionNodesIterator
C ConcurrentHnswMerger
C DenseNodesIterator
C FilteredHnswGraphSearcher
C FloatHeap
C GraphBuilderKnnCollector
I HasKnnVectorValues
I HnswBuilder
C HnswConcurrentMergeBuilder
C HnswGraph
C HnswGraphBuilder
I HnswGraphMerger
C HnswGraphSearcher
C HnswUtil
C IncrementalHnswGraphMerger
C InitializedHnswGraphBuilder
I IntToIntFunction
C MergingHnswGraphBuilder
C NeighborArray
C NeighborQueue
C NodesIterator
C OnHeapHnswGraph
C OrdinalTranslatedKnnCollector
I RandomVectorScorer
I RandomVectorScorerSupplier
C UpdateGraphsUtils
I UpdateableRandomVectorScorer
HnswGraphSearcher — members 6+
C new(candidates, visited)
M expected_visited_nodes(k, graph_size) int
M search(scorer, knn_collector, graph, accept_ords)
M search(scorer, knn_collector, graph, accept_ords, filtered_doc_count)
M search(scorer, top_k, graph, accept_ords, visited_limit) KnnCollector
M search_level(scorer, top_k, level, eps, graph) GraphBuilderKnnCollector
from AbstractHnswGraphSearcher
M search(results, scorer, graph, accept_ords)

org.apache.lucene.util.hnsw.HnswGraphSearcher

class extends AbstractHnswGraphSearcher 6 members

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

Constructors

new

new ( NeighborQueue candidates, BitSet visited )
Java: <init>(org.apache.lucene.util.hnsw.NeighborQueue candidates, org.apache.lucene.util.BitSet visited)

Creates a new graph searcher.

nametypedescription
candidatesorg.apache.lucene.util.hnsw.NeighborQueuemax heap that will track the candidate nodes to explore
visitedorg.apache.lucene.util.BitSetbit set that will track nodes that have already been visited

Class Methods

expected_visited_nodes

int expected_visited_nodes ( int k, int graph_size )
Java: expectedVisitedNodes(int k, int graphSize)

HNSW search is roughly logarithmic. This doesn't take maxConn into account, but it is a pretty good approximation.

nametypedescription
kintneighbors to find
graph_sizeintsize of the graph

Returns: expected number of visited nodes

search

search ( RandomVectorScorer scorer, KnnCollector knn_collector, HnswGraph graph, Bits accept_ords )
Java: search(org.apache.lucene.util.hnsw.RandomVectorScorer scorer, org.apache.lucene.search.KnnCollector knnCollector, org.apache.lucene.util.hnsw.HnswGraph graph, org.apache.lucene.util.Bits acceptOrds)

See HnswGraphSearcher#search(RandomVectorScorer, KnnCollector, HnswGraph, Bits, int)

nametypedescription
scorerorg.apache.lucene.util.hnsw.RandomVectorScorerthe scorer to compare the query with the nodes
knn_collectororg.apache.lucene.search.KnnCollectora hnsw knn collector of top knn results to be returned
graphorg.apache.lucene.util.hnsw.HnswGraphthe graph values. May represent the entire graph, or a level in a hierarchical graph.
accept_ordsorg.apache.lucene.util.BitsBits that represents the allowed document ordinals to match, or null if they are all allowed to match.

search

search ( RandomVectorScorer scorer, KnnCollector knn_collector, HnswGraph graph, Bits accept_ords, int filtered_doc_count )
Java: search(org.apache.lucene.util.hnsw.RandomVectorScorer scorer, org.apache.lucene.search.KnnCollector knnCollector, org.apache.lucene.util.hnsw.HnswGraph graph, org.apache.lucene.util.Bits acceptOrds, int filteredDocCount)

Searches the HNSW graph for the nearest neighbors of a query vector. If entry points are directly provided via the knnCollector, then the search will be initialized at those points. Otherwise, the search will discover the best entry point per the normal HNSW search algorithm.

nametypedescription
scorerorg.apache.lucene.util.hnsw.RandomVectorScorerthe scorer to compare the query with the nodes
knn_collectororg.apache.lucene.search.KnnCollectora hnsw knn collector of top knn results to be returned
graphorg.apache.lucene.util.hnsw.HnswGraphthe graph values. May represent the entire graph, or a level in a hierarchical graph.
accept_ordsorg.apache.lucene.util.BitsBits that represents the allowed document ordinals to match, or null if they are all allowed to match.
filtered_doc_countintthe number of docs that pass the filter

search

KnnCollector search ( RandomVectorScorer scorer, int top_k, OnHeapHnswGraph graph, Bits accept_ords, int visited_limit )
Java: search(org.apache.lucene.util.hnsw.RandomVectorScorer scorer, int topK, org.apache.lucene.util.hnsw.OnHeapHnswGraph graph, org.apache.lucene.util.Bits acceptOrds, int visitedLimit)

Search OnHeapHnswGraph, this method is thread safe.

nametypedescription
scorerorg.apache.lucene.util.hnsw.RandomVectorScorerthe scorer to compare the query with the nodes
top_kintthe number of nodes to be returned
graphorg.apache.lucene.util.hnsw.OnHeapHnswGraphthe graph values. May represent the entire graph, or a level in a hierarchical graph.
accept_ordsorg.apache.lucene.util.BitsBits that represents the allowed document ordinals to match, or null if they are all allowed to match.
visited_limitintthe maximum number of nodes that the search is allowed to visit

Returns: a set of collected vectors holding the nearest neighbors found

Instance Methods

search_level

HnswGraphBuilder.GraphBuilderKnnCollector search_level ( RandomVectorScorer scorer, int top_k, int level, int[] eps, HnswGraph graph )
Java: searchLevel(org.apache.lucene.util.hnsw.RandomVectorScorer scorer, int topK, int level, int[] eps, org.apache.lucene.util.hnsw.HnswGraph graph)

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

If the search stops early because it reaches the visited nodes limit, then the results will be marked incomplete through NeighborQueue#incomplete().

nametypedescription
scorerorg.apache.lucene.util.hnsw.RandomVectorScorerthe scorer to compare the query with the nodes
top_kintthe number of nearest to query results to return
levelintlevel to search
epsint[]the entry points for search at this level expressed as level 0th ordinals
graphorg.apache.lucene.util.hnsw.HnswGraphthe graph values

Returns: a set of collected vectors holding the nearest neighbors found

Inherited

from AbstractHnswGraphSearcher

search

search ( KnnCollector results, RandomVectorScorer scorer, HnswGraph graph, Bits accept_ords )
Java: search(org.apache.lucene.search.KnnCollector results, org.apache.lucene.util.hnsw.RandomVectorScorer scorer, org.apache.lucene.util.hnsw.HnswGraph graph, org.apache.lucene.util.Bits acceptOrds)

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

nametypedescription
resultsorg.apache.lucene.search.KnnCollectorthe collector to collect the results
scorerorg.apache.lucene.util.hnsw.RandomVectorScorerthe scorer to compare the query with the nodes
graphorg.apache.lucene.util.hnsw.HnswGraphthe HNSWGraph
accept_ordsorg.apache.lucene.util.Bitsthe ordinals to accept for the results

Throws

IOException When accessing the vectors or graph fails
this work for additional information regarding copyright ownership.