java.lang.Object
org.apache.lucene.search.Query
org.apache.lucene.search.AbstractKnnVectorQuery
org.apache.lucene.search.KnnByteVectorQuery
- Direct Known Subclasses:
DiversifyingChildrenByteKnnVectorQuery
Uses
KnnVectorsReader.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
FieldsFields inherited from class org.apache.lucene.search.AbstractKnnVectorQuery
field, k -
Constructor Summary
ConstructorsConstructorDescriptionKnnByteVectorQuery(String field, byte[] target, int k) Find theknearest documents to the target vector according to the vectors in the given field.KnnByteVectorQuery(String field, byte[] target, int k, Query filter) Find theknearest documents to the target vector according to the vectors in the given field. -
Method Summary
Modifier and TypeMethodDescriptionprotected TopDocsapproximateSearch(LeafReaderContext context, Bits acceptDocs, int visitedLimit, KnnCollectorManager knnCollectorManager) (package private) VectorScorercreateVectorScorer(LeafReaderContext context, FieldInfo fi) booleanOverride and implement query instance equivalence properly in a subclass.byte[]inthashCode()Override and implement query hash code properly in a subclass.Prints a query to a string, withfieldassumed to be the default field and omitted.Methods inherited from class org.apache.lucene.search.AbstractKnnVectorQuery
exactSearch, findSegmentStarts, getField, getFilter, getK, getKnnCollectorManager, mergeLeafResults, rewrite, visitMethods inherited from class org.apache.lucene.search.Query
classHash, createWeight, rewrite, sameClassAs, toString
-
Field Details
-
NO_RESULTS
-
target
private final byte[] target
-
-
Constructor Details
-
KnnByteVectorQuery
Find theknearest documents to the target vector according to the vectors in the given field.targetvector.- Parameters:
field- a field that has been indexed as aKnnFloatVectorField.target- the target of the searchk- the number of documents to find- Throws:
IllegalArgumentException- ifkis less than 1
-
KnnByteVectorQuery
Find theknearest documents to the target vector according to the vectors in the given field.targetvector.- 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:
IllegalArgumentException- ifkis less than 1
-
-
Method Details
-
approximateSearch
protected TopDocs approximateSearch(LeafReaderContext context, Bits acceptDocs, int visitedLimit, KnnCollectorManager knnCollectorManager) throws IOException - Specified by:
approximateSearchin classAbstractKnnVectorQuery- Throws:
IOException
-
createVectorScorer
- Specified by:
createVectorScorerin classAbstractKnnVectorQuery- Throws:
IOException
-
toString
Description copied from class:QueryPrints a query to a string, withfieldassumed to be the default field and omitted. -
equals
Description copied from class:QueryOverride and implement query instance equivalence properly in a subclass. This is required so thatQueryCacheworks 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:
equalsin classAbstractKnnVectorQuery- See Also:
-
hashCode
public int hashCode()Description copied from class:QueryOverride and implement query hash code properly in a subclass. This is required so thatQueryCacheworks properly.- Overrides:
hashCodein classAbstractKnnVectorQuery- See Also:
-
getTargetCopy
public byte[] getTargetCopy()- Returns:
- the target query vector of the search. Each vector element is a byte.
-