Package org.apache.lucene.util.hnsw
Class FilteredHnswGraphSearcher
java.lang.Object
org.apache.lucene.util.hnsw.HnswGraphSearcher
org.apache.lucene.util.hnsw.FilteredHnswGraphSearcher
Searches an HNSW graph to find nearest neighbors to a query vector. This particular
implementation is optimized for a filtered search, inspired by the ACORN-1 algorithm.
https://arxiv.org/abs/2403.04871 However, this implementation is augmented in some ways, mainly:
- It dynamically determines when the optimized filter step should occur based on some filtered lambda. This is done per small world
- The graph searcher doesn't always explore all the extended neighborhood and the number of additional candidates is predicated on the original candidate's filtered percentage.
-
Field Summary
Fields inherited from class org.apache.lucene.util.hnsw.HnswGraphSearcher
candidates, visited
-
Method Summary
Modifier and TypeMethodDescriptionstatic FilteredHnswGraphSearcher
Creates a new filtered graph searcher.void
search
(KnnCollector results, RandomVectorScorer scorer, HnswGraph graph, Bits acceptOrds) Search the graph for the given scorer.Methods inherited from class org.apache.lucene.util.hnsw.HnswGraphSearcher
search, search, search, searchLevel
-
Method Details
-
create
public static FilteredHnswGraphSearcher create(int k, HnswGraph graph, int filterSize, Bits acceptOrds) Creates a new filtered graph searcher.- Parameters:
k
- the number of nearest neighbors to findgraph
- the graph to searchfilterSize
- the number of vectors that pass the accepted ords filteracceptOrds
- the accepted ords filter- Returns:
- a new graph searcher optimized for filtered search
-
search
public void search(KnnCollector results, RandomVectorScorer scorer, HnswGraph graph, Bits acceptOrds) throws IOException Search the graph for the given scorer. Gathering results in the provided collector that pass the provided acceptOrds.- Parameters:
results
- the collector to collect the resultsscorer
- the scorer to compare the query with the nodesgraph
- the HNSWGraphacceptOrds
- the ordinals to accept for the results- Throws:
IOException
- When accessing the vectors or graph fails
-