spamosaic.utils.nn_approx

spamosaic.utils.nn_approx(ds1, ds2, norm=True, knn=10, metric='manhattan', n_trees=10, include_distances=False)[source]

Performs approximate nearest neighbor search using Annoy.

Parameters:
  • ds1 (np.ndarray) – Query data (n_samples, n_features).

  • ds2 (np.ndarray) – Reference data (n_samples, n_features).

  • norm (bool) – Whether to normalize data before search.

  • knn (int) – Number of nearest neighbors to retrieve.

  • metric (str) – Distance metric for Annoy (e.g., ‘manhattan’).

  • n_trees (int) – Number of trees used by Annoy.

  • include_distances (bool) – Whether to return distances with indices.

Returns:

Indices of nearest neighbors, optionally with distances.

Return type:

np.ndarray or tuple