<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "NaturalLanguage",
  "identifier" : "/documentation/NaturalLanguage/NLEmbedding/neighbors(for:maximumCount:distanceType:)-8lp4z",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Natural Language",
      "NaturalLanguage"
    ],
    "preciseIdentifier" : "s:So11NLEmbeddingC15NaturalLanguageE9neighbors3for12maximumCount12distanceTypeSaySS_SdtGSaySdG_SiSo010NLDistanceI0VtF"
  },
  "title" : "neighbors(for:maximumCount:distanceType:)"
}
-->

# neighbors(for:maximumCount:distanceType:)

Retrieves a limited number of strings near a location in the vocabulary space.

```
@nonobjc func neighbors(for vector: [Double], maximumCount maxCount: Int, distanceType: NLDistanceType = .cosine) -> [(String, NLDistance)]
```

## Parameters

`vector`

A location in the vocabulary space.

`maxCount`

The largest number of neighboring strings that the method can return in an array.

`distanceType`

A means of calculating distance that determines which formula the method uses to evaluate a neighbor’s distance from `vector`.

## Return Value

An array of neighboring strings and their distances.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)