- java.lang.Object
-
- org.apache.lucene.search.Query
-
- org.apache.lucene.search.AbstractKnnVectorQuery
-
- org.apache.lucene.search.KnnByteVectorQuery
-
- Direct Known Subclasses:
DiversifyingChildrenByteKnnVectorQuery
public class KnnByteVectorQuery extends AbstractKnnVectorQuery
UsesKnnVectorsReader.search(String, byte[], KnnCollector, Bits)
to perform nearest neighbour search.This query also allows for performing a kNN search subject to a filter. In this case, it first executes the filter for each leaf, then chooses a strategy dynamically:
- If the filter cost is less than k, just execute an exact search
- Otherwise run a kNN search subject to the filter
- If the kNN search visits too many vectors without completing, stop and run an exact search
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.lucene.search.AbstractKnnVectorQuery
AbstractKnnVectorQuery.DocAndScoreQuery
-
-
Field Summary
Fields Modifier and Type Field Description private static TopDocs
NO_RESULTS
private byte[]
target
-
Fields inherited from class org.apache.lucene.search.AbstractKnnVectorQuery
field, k
-
-
Constructor Summary
Constructors Constructor Description KnnByteVectorQuery(java.lang.String field, byte[] target, int k)
Find thek
nearest documents to the target vector according to the vectors in the given field.KnnByteVectorQuery(java.lang.String field, byte[] target, int k, Query filter)
Find thek
nearest documents to the target vector according to the vectors in the given field.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected TopDocs
approximateSearch(LeafReaderContext context, Bits acceptDocs, int visitedLimit)
(package private) VectorScorer
createVectorScorer(LeafReaderContext context, FieldInfo fi)
boolean
equals(java.lang.Object o)
Override and implement query instance equivalence properly in a subclass.byte[]
getTargetCopy()
int
hashCode()
Override and implement query hash code properly in a subclass.java.lang.String
toString(java.lang.String field)
Prints a query to a string, withfield
assumed to be the default field and omitted.-
Methods inherited from class org.apache.lucene.search.AbstractKnnVectorQuery
exactSearch, findSegmentStarts, getField, getFilter, getK, mergeLeafResults, rewrite, visit
-
Methods inherited from class org.apache.lucene.search.Query
classHash, createWeight, rewrite, sameClassAs, toString
-
-
-
-
Field Detail
-
NO_RESULTS
private static final TopDocs NO_RESULTS
-
target
private final byte[] target
-
-
Constructor Detail
-
KnnByteVectorQuery
public KnnByteVectorQuery(java.lang.String field, byte[] target, int k)
Find thek
nearest documents to the target vector according to the vectors in the given field.target
vector.- Parameters:
field
- a field that has been indexed as aKnnFloatVectorField
.target
- the target of the searchk
- the number of documents to find- Throws:
java.lang.IllegalArgumentException
- ifk
is less than 1
-
KnnByteVectorQuery
public KnnByteVectorQuery(java.lang.String field, byte[] target, int k, Query filter)
Find thek
nearest documents to the target vector according to the vectors in the given field.target
vector.- Parameters:
field
- a field that has been indexed as aKnnFloatVectorField
.target
- the target of the searchk
- the number of documents to findfilter
- a filter applied before the vector search- Throws:
java.lang.IllegalArgumentException
- ifk
is less than 1
-
-
Method Detail
-
approximateSearch
protected TopDocs approximateSearch(LeafReaderContext context, Bits acceptDocs, int visitedLimit) throws java.io.IOException
- Specified by:
approximateSearch
in classAbstractKnnVectorQuery
- Throws:
java.io.IOException
-
createVectorScorer
VectorScorer createVectorScorer(LeafReaderContext context, FieldInfo fi) throws java.io.IOException
- Specified by:
createVectorScorer
in classAbstractKnnVectorQuery
- Throws:
java.io.IOException
-
toString
public java.lang.String toString(java.lang.String field)
Description copied from class:Query
Prints a query to a string, withfield
assumed to be the default field and omitted.
-
equals
public boolean equals(java.lang.Object o)
Description copied from class:Query
Override and implement query instance equivalence properly in a subclass. This is required so thatQueryCache
works properly.Typically a query will be equal to another only if it's an instance of the same class and its document-filtering properties are identical to those of the other instance. Utility methods are provided for certain repetitive code.
- Overrides:
equals
in classAbstractKnnVectorQuery
- See Also:
Query.sameClassAs(Object)
,Query.classHash()
-
hashCode
public int hashCode()
Description copied from class:Query
Override and implement query hash code properly in a subclass. This is required so thatQueryCache
works properly.- Overrides:
hashCode
in classAbstractKnnVectorQuery
- See Also:
Query.equals(Object)
-
getTargetCopy
public byte[] getTargetCopy()
- Returns:
- the target query vector of the search. Each vector element is a byte.
-
-