java.lang.Object
org.apache.lucene.search.Query
org.apache.lucene.search.AbstractKnnVectorQuery
org.apache.lucene.search.KnnFloatVectorQuery
- Direct Known Subclasses:
DiversifyingChildrenFloatKnnVectorQuery
,KnnVectorQuery
Uses
KnnVectorsReader.search(String, float[], 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
ConstructorsConstructorDescriptionKnnFloatVectorQuery
(String field, float[] target, int k) Find thek
nearest documents to the target vector according to the vectors in the given field.KnnFloatVectorQuery
(String field, float[] target, int k, Query filter) Find thek
nearest documents to the target vector according to the vectors in the given field. -
Method Summary
Modifier and TypeMethodDescriptionprotected TopDocs
approximateSearch
(LeafReaderContext context, Bits acceptDocs, int visitedLimit, KnnCollectorManager knnCollectorManager) (package private) VectorScorer
createVectorScorer
(LeafReaderContext context, FieldInfo fi) boolean
Override and implement query instance equivalence properly in a subclass.float[]
int
hashCode()
Override and implement query hash code properly in a subclass.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, getKnnCollectorManager, mergeLeafResults, rewrite, visit
Methods inherited from class org.apache.lucene.search.Query
classHash, createWeight, rewrite, sameClassAs, toString
-
Field Details
-
NO_RESULTS
-
target
private final float[] target
-
-
Constructor Details
-
KnnFloatVectorQuery
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:
IllegalArgumentException
- ifk
is less than 1
-
KnnFloatVectorQuery
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:
IllegalArgumentException
- ifk
is less than 1
-
-
Method Details
-
approximateSearch
protected TopDocs approximateSearch(LeafReaderContext context, Bits acceptDocs, int visitedLimit, KnnCollectorManager knnCollectorManager) throws IOException - Specified by:
approximateSearch
in classAbstractKnnVectorQuery
- Throws:
IOException
-
createVectorScorer
- Specified by:
createVectorScorer
in classAbstractKnnVectorQuery
- Throws:
IOException
-
toString
Description copied from class:Query
Prints a query to a string, withfield
assumed to be the default field and omitted. -
equals
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:
-
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:
-
getTargetCopy
public float[] getTargetCopy()- Returns:
- the target query vector of the search. Each vector element is a float.
-