Package io.github.jbellis.jvector.graph
Class GraphSearcher<T>
java.lang.Object
io.github.jbellis.jvector.graph.GraphSearcher<T>
Searches a graph to find nearest neighbors to a query vector. For more background on the
search algorithm, see
GraphIndex.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionresume(int additionalK) Experimental!resume(int additionalK, float threshold, float rerankFloor) Experimental!search(NodeSimilarity.ScoreFunction scoreFunction, NodeSimilarity.Reranker reranker, int topK, float threshold, float rerankFloor, Bits acceptOrds) search(NodeSimilarity.ScoreFunction scoreFunction, NodeSimilarity.Reranker reranker, int topK, float threshold, Bits acceptOrds) search(NodeSimilarity.ScoreFunction scoreFunction, NodeSimilarity.Reranker reranker, int topK, Bits acceptOrds) static <T> SearchResultsearch(T targetVector, int topK, RandomAccessVectorValues<T> vectors, VectorEncoding vectorEncoding, VectorSimilarityFunction similarityFunction, GraphIndex<T> graph, Bits acceptOrds) Convenience function for simple one-off searches.
-
Method Details
-
search
public static <T> SearchResult search(T targetVector, int topK, RandomAccessVectorValues<T> vectors, VectorEncoding vectorEncoding, VectorSimilarityFunction similarityFunction, GraphIndex<T> graph, Bits acceptOrds) Convenience function for simple one-off searches. It is caller's responsibility to make sure that it is the unique owner of the vectors instance passed in here. -
search
public SearchResult search(NodeSimilarity.ScoreFunction scoreFunction, NodeSimilarity.Reranker reranker, int topK, float threshold, float rerankFloor, Bits acceptOrds) - Parameters:
scoreFunction- a function returning the similarity of a given node to the query vectorreranker- if scoreFunction is approximate, this should be non-null and perform exact comparisons of the vectors for re-ranking at the end of the search.topK- the number of results to look for. With threshold=0, the search will continue until at least `topK` results have been found, or until the entire graph has been searched.threshold- the minimum similarity (0..1) to accept; 0 will accept everything. May be used with a large topK to find (approximately) all nodes above the given threshold. If threshold > 0 then the search will stop when it is probabilistically unlikely to find more nodes above the threshold, even if `topK` results have not yet been found.rerankFloor- (Experimental!) Candidates whose approximate similarity is at least this value will not be reranked with the exact score (which requires loading the raw vector) and included in the final results. (Potentially leaving fewer than topK entries in the results.) Other candidates will be discarded. This is intended for use when combining results from multiple indexes.acceptOrds- a Bits instance indicating which nodes are acceptable results. IfBits.ALL, all nodes are acceptable. It is caller's responsibility to ensure that there are enough acceptable nodes that we don't search the entire graph trying to satisfy topK.- Returns:
- a SearchResult containing the topK results and the number of nodes visited during the search.
-
search
public SearchResult search(NodeSimilarity.ScoreFunction scoreFunction, NodeSimilarity.Reranker reranker, int topK, float threshold, Bits acceptOrds) - Parameters:
scoreFunction- a function returning the similarity of a given node to the query vectorreranker- if scoreFunction is approximate, this should be non-null and perform exact comparisons of the vectors for re-ranking at the end of the search.topK- the number of results to look for. With threshold=0, the search will continue until at least `topK` results have been found, or until the entire graph has been searched.threshold- the minimum similarity (0..1) to accept; 0 will accept everything. May be used with a large topK to find (approximately) all nodes above the given threshold. If threshold > 0 then the search will stop when it is probabilistically unlikely to find more nodes above the threshold, even if `topK` results have not yet been found.acceptOrds- a Bits instance indicating which nodes are acceptable results. IfBits.ALL, all nodes are acceptable. It is caller's responsibility to ensure that there are enough acceptable nodes that we don't search the entire graph trying to satisfy topK.- Returns:
- a SearchResult containing the topK results and the number of nodes visited during the search.
-
search
public SearchResult search(NodeSimilarity.ScoreFunction scoreFunction, NodeSimilarity.Reranker reranker, int topK, Bits acceptOrds) - Parameters:
scoreFunction- a function returning the similarity of a given node to the query vectorreranker- if scoreFunction is approximate, this should be non-null and perform exact comparisons of the vectors for re-ranking at the end of the search.topK- the number of results to look for. With threshold=0, the search will continue until at least `topK` results have been found, or until the entire graph has been searched.acceptOrds- a Bits instance indicating which nodes are acceptable results. IfBits.ALL, all nodes are acceptable. It is caller's responsibility to ensure that there are enough acceptable nodes that we don't search the entire graph trying to satisfy topK.- Returns:
- a SearchResult containing the topK results and the number of nodes visited during the search.
-
resume
Experimental!Resume the previous search where it left off and search for the best `additionalK` neighbors. It is NOT valid to call this method before calling `search`, but `resume` may be called as many times as desired once the search is initialized.
SearchResult.visitedCount resets with each call to `search` or `resume`.
-
resume
Experimental!Resume the previous search where it left off and search for the best `additionalK` neighbors. It is NOT valid to call this method before calling `search`, but `resume` may be called as many times as desired once the search is initialized.
SearchResult.visitedCount resets with each call to `search` or `resume`.
-