class_docstr: Patchcore Module.
class_docstr_tok: ["Patchcore","Module","."]
docstr: Nearest Neighbours using brute force method and euclidean norm.
  
  Args:
      embedding (Tensor): Features to compare the distance with the memory bank.
      n_neighbors (int): Number of neighbors to look at
  
  Returns:
      Tensor: Patch scores.
      Tensor: Locations of the nearest neighbor(s).
docstr_tok: ["Nearest","Neighbours","using","brute","force","method","and","euclidean","norm",".","Args",":","embedding","(","Tensor",")",":","Features","to","compare","the","distance","with","the","memory","bank",".","n_neighbors","(","int",")",":","Number","of","neighbors","to","look","at","Returns",":","Tensor",":","Patch","scores",".","Tensor",":","Locations","of","the","nearest","neighbor","(","s",")","."]
code: def nearest_neighbors(
      self, embedding: Tensor, n_neighbors: int
  ) -> tuple[Tensor, Tensor]:
      """Nearest Neighbours using brute force method and euclidean norm.
  
      Args:
          embedding (Tensor): Features to compare the distance with the memory bank.
          n_neighbors (int): Number of neighbors to look at
  
      Returns:
          Tensor: Patch scores.
          Tensor: Locations of the nearest neighbor(s).
      """
      distances = self.euclidean_dist(embedding, self.memory_bank)
      if n_neighbors == 1:
          # when n_neighbors is 1, speed up computation by using min instead of topk
          patch_scores, locations = distances.min(1)
      else:
          patch_scores, locations = distances.topk(
              k=n_neighbors, largest=False, dim=1
          )
      return patch_scores, locations
  
file_path: anomalib/src/anomalib/models/patchcore/torch_model.py
imports: from __future__ import annotations
  import torch
  import torch.nn.functional
  from torch import Tensor, nn
  from anomalib.models.components import DynamicBufferModule, FeatureExtractor, KCenterGreedy
  from anomalib.models.patchcore.anomaly_map import AnomalyMapGenerator
  from anomalib.pre_processing import Tiler
label_desc: Use image node_id 7 for calling the PatchcoreModel obj's underlying member method code with example usage: obj.nearest_neighbors(embedding, n_neighbors) and returns: patch_scores,  locations