HnswGraphBuilder.GraphBuilderKnnCollector (Lucene 10.5.0 core API)
Description: declaration: package: org.apache.lucene.util.hnsw, class: HnswGraphBuilder, class: GraphBuilderKnnCollector

Package org.apache.lucene.util.hnsw

# Class HnswGraphBuilder.GraphBuilderKnnCollector

java.lang.Object
org.apache.lucene.util.hnsw.HnswGraphBuilder.GraphBuilderKnnCollector

All Implemented Interfaces:
  `KnnCollector`

Enclosing class:
  `HnswGraphBuilder`

public static final class HnswGraphBuilder.GraphBuilderKnnCollector extends Object implements KnnCollector
A restricted, specialized knnCollector that can be used when building a graph.

Does not support TopDocs

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface org.apache.lucene.search.KnnCollector

  `KnnCollector.Decorator`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GraphBuilderKnnCollector(int k)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  `boolean`
  `collect(int docId, float similarity)`
  Collect the provided docId and include in the result set.
  `boolean`
  `earlyTerminated()`
  If search visits too many documents, the results collector will terminate early.
  `KnnSearchStrategy`
  `getSearchStrategy()`
  `void`
  `incVisitedCount(int count)`
  `int`
  `k()`
  `float`
  `minCompetitiveSimilarity()`
  This method is utilized during search to ensure only competitive results are explored.
  `int`
  `popNode()`
  `int[]`
  `popUntilNearestKNodes()`
  `int`
  `size()`
  `TopDocs`
  `topDocs()`
  This drains the collected nearest kNN results and returns them in a new `TopDocs` collection, ordered by score descending.
  `long`
  `visitedCount()`
  `long`
  `visitLimit()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### GraphBuilderKnnCollector

    public GraphBuilderKnnCollector(int k)
    Parameters:
      `k` - the number of neighbors to collect

- ## Method Details

  - ### size

    public int size()

  - ### popNode

    public int popNode()

  - ### popUntilNearestKNodes

    public int[] popUntilNearestKNodes()

  - ### clear

    public void clear()

  - ### earlyTerminated

    public boolean earlyTerminated()
    Description copied from interface: `KnnCollector`
    If 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:
      `earlyTerminated` in interface `KnnCollector`
    Returns:
      is the current result set marked as incomplete?

  - ### incVisitedCount

    public void incVisitedCount(int count)
    Specified by:
      `incVisitedCount` in interface `KnnCollector`
    Parameters:
      `count` - increments the visited vector count, must be greater than 0.

  - ### visitedCount

    public long visitedCount()
    Specified by:
      `visitedCount` in interface `KnnCollector`
    Returns:
      the current visited vector count

  - ### visitLimit

    public long visitLimit()
    Specified by:
      `visitLimit` in interface `KnnCollector`
    Returns:
      the visited vector limit

  - ### k

    public int k()
    Specified by:
      `k` in interface `KnnCollector`
    Returns:
      the expected number of collected results

  - ### collect

    public boolean collect(int docId, float similarity)
    Description copied from interface: `KnnCollector`
    Collect the provided docId and include in the result set.
    Specified by:
      `collect` in interface `KnnCollector`
    Parameters:
      `docId` - of the vector to collect
      `similarity` - its calculated similarity
    Returns:
      true if the vector is collected

  - ### minCompetitiveSimilarity

    public float minCompetitiveSimilarity()
    Description copied from interface: `KnnCollector`
    This 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_INFINITY` when not full.

    When full, the minimum score should be returned.

    Specified by:
      `minCompetitiveSimilarity` in interface `KnnCollector`
    Returns:
      the current minimum competitive similarity in the collection

  - ### topDocs

    public TopDocs topDocs()
    Description copied from interface: `KnnCollector`
    This drains the collected nearest kNN results and returns them in a new `TopDocs` collection, ordered by score descending. NOTE: This is generally a destructive action and the collector should not be used after topDocs() is called.
    Specified by:
      `topDocs` in interface `KnnCollector`
    Returns:
      The collected top documents

  - ### getSearchStrategy

    public KnnSearchStrategy getSearchStrategy()
    Specified by:
      `getSearchStrategy` in interface `KnnCollector`
    Returns:
      the search strategy used by this collector, can be null