Package org.apache.lucene.util.hnsw
Class OrdinalTranslatedKnnCollector
- java.lang.Object
-
- org.apache.lucene.util.hnsw.OrdinalTranslatedKnnCollector
-
- All Implemented Interfaces:
KnnCollector
public final class OrdinalTranslatedKnnCollector extends Object implements KnnCollector
Wraps a provided KnnCollector object, translating the provided vectorId ordinal to a documentId
-
-
Constructor Summary
Constructors Constructor Description OrdinalTranslatedKnnCollector(KnnCollector in, IntToIntFunction vectorOrdinalToDocId)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancollect(int vectorId, float similarity)Collect the provided docId and include in the result set.booleanearlyTerminated()If search visits too many documents, the results collector will terminate early.voidincVisitedCount(int count)intk()floatminCompetitiveSimilarity()This method is utilized during search to ensure only competitive results are explored.TopDocstopDocs()This drains the collected nearest kNN results and returns them in a newTopDocscollection, ordered by score descending.longvisitedCount()longvisitLimit()
-
-
-
Constructor Detail
-
OrdinalTranslatedKnnCollector
public OrdinalTranslatedKnnCollector(KnnCollector in, IntToIntFunction vectorOrdinalToDocId)
-
-
Method Detail
-
earlyTerminated
public boolean earlyTerminated()
Description copied from interface:KnnCollectorIf search visits too many documents, the results collector will terminate early. Usually, this is due to some restricted filter on the document set.When collection is earlyTerminated, the results are not a correct representation of k nearest neighbors.
- Specified by:
earlyTerminatedin interfaceKnnCollector- Returns:
- is the current result set marked as incomplete?
-
incVisitedCount
public void incVisitedCount(int count)
- Specified by:
incVisitedCountin interfaceKnnCollector- Parameters:
count- increments the visited vector count, must be greater than 0.
-
visitedCount
public long visitedCount()
- Specified by:
visitedCountin interfaceKnnCollector- Returns:
- the current visited vector count
-
visitLimit
public long visitLimit()
- Specified by:
visitLimitin interfaceKnnCollector- Returns:
- the visited vector limit
-
k
public int k()
- Specified by:
kin interfaceKnnCollector- Returns:
- the expected number of collected results
-
collect
public boolean collect(int vectorId, float similarity)Description copied from interface:KnnCollectorCollect the provided docId and include in the result set.- Specified by:
collectin interfaceKnnCollector- Parameters:
vectorId- of the vector to collectsimilarity- its calculated similarity- Returns:
- true if the vector is collected
-
minCompetitiveSimilarity
public float minCompetitiveSimilarity()
Description copied from interface:KnnCollectorThis method is utilized during search to ensure only competitive results are explored.Consequently, if this results collector wants to collect `k` results, this should return
Float.NEGATIVE_INFINITYwhen not full.When full, the minimum score should be returned.
- Specified by:
minCompetitiveSimilarityin interfaceKnnCollector- Returns:
- the current minimum competitive similarity in the collection
-
topDocs
public TopDocs topDocs()
Description copied from interface:KnnCollectorThis drains the collected nearest kNN results and returns them in a newTopDocscollection, ordered by score descending. NOTE: This is generally a destructive action and the collector should not be used after topDocs() is called.- Specified by:
topDocsin interfaceKnnCollector- Returns:
- The collected top documents
-
-