Outputs from approximate nearest neighbors - Outputs from approximate nearest neighbors - 5.3 English - 68552

AOCL API Guide (68552)

Document_ID
68552
Release_Date
2026-05-13
Version
5.3 English

After training and adding data to the index, the following results are stored:

  • cluster centroids - the \(n_{list}\) centroids computed by k-means clustering during training. Each centroid is a vector of length \(n_{features}\).

  • list sizes - the number of data points assigned to each centroid. This is an array of length \(n_{list}\).

  • n_list - the number of lists in the index.

  • n_index - the number of data points that have been added to the index.

  • n_features - the number of features (dimensions) of the data.

  • k-means iterations - the number of k-means iterations performed during training.

After querying the index with kneighbors(), the following results are returned:

  • indices of nearest neighbors - the indices of the approximate nearest neighbors for each query point, provided in order of distance (closest first).

  • distances to the nearest neighbors (optional) - the corresponding distances from each query point to its neighbors.

Note

When querying the index, if the total number of data points stored across the \(n_{probe}\) closest centroids is less than the requested number of neighbors \(k\), fewer than \(k\) valid neighbors will be returned. In this case, the remaining entries in the output arrays are filled with sentinel values:

  • indices: set to \(-1\)

  • distances: set to positive infinity for euclidean, sqeuclidean, and cosine metrics, or negative infinity for inner product

This situation can occur when \(n_{probe}\) is small and the probed centroids happen to contain few data points. To avoid this, ensure that enough centroids are probed or that the index contains sufficient data. The list_sizes output can be used to check how many data points are assigned to each centroid after adding data to the index. If each list contains at least \(k\) data points, then any query will be guaranteed to return \(k\) valid neighbors.